let''s say I have a pointer to some bytes
BYTE * pmyBytes;
int * pmyInt;
and let''s say the address is "101"
How do I read data off of the memory that pointer points to?
pmyInt = (int *)pmyBytes; //This should read 4 bytes from address "101" on right?
Now let''s say I want to start reading from address "105" ... how would I do that?
I think you can use pmyBytes++ to increase where pmyBytes points to. Or you can use pmyBytes[Offset].
If you want to the the value contained at a pointers address, use the ''*'' operator.
Example:
int *iPtr;
int iVar;
int iVar2;
iVar=4;
iPtr=iVar;
iVar2=*iPtr;
//^would set iVar=iVar2
As for your situation, I *think* something like this would work:
iSomeIntYouDeclared=*(int)pmyBytes;
The thing you have now would set pmyInt to the _location_ of whatever pmyBytes points to. ...I think.
If something is at address 101 and you wanted to read something at address 105, you''d have to do something like: iVar=*(pBytes+4);
Out of curiosity, what exactly are you trying to do?
Btw, I''m fairly sure I missed something, or posted an inacurracy or two. Hopefully someone will correct me.
Example:
int *iPtr;
int iVar;
int iVar2;
iVar=4;
iPtr=iVar;
iVar2=*iPtr;
//^would set iVar=iVar2
As for your situation, I *think* something like this would work:
iSomeIntYouDeclared=*(int)pmyBytes;
The thing you have now would set pmyInt to the _location_ of whatever pmyBytes points to. ...I think.
If something is at address 101 and you wanted to read something at address 105, you''d have to do something like: iVar=*(pBytes+4);
Out of curiosity, what exactly are you trying to do?
Btw, I''m fairly sure I missed something, or posted an inacurracy or two. Hopefully someone will correct me.
A. Buza, whenever you sign a pointer to a variable you must use the address of operator "&" thus:
int *iPtr;
int iVar;
int iVar2;
iVar=4;
iPtr=&iVar
iVar2=*iPtr;
But anyways back to my situation. What I''m trying to do is that, open a file and read everything in a pointer to a memory block. Then, read the information from the pointer.
int *iPtr;
int iVar;
int iVar2;
iVar=4;
iPtr=&iVar
iVar2=*iPtr;
But anyways back to my situation. What I''m trying to do is that, open a file and read everything in a pointer to a memory block. Then, read the information from the pointer.
quote:
BYTE *pmyBytes;
int *pmyInt;
and let''s say the address is "101"
How do I read data off of the memory that pointer points to?
pmyInt = (int *)pmyBytes; //This should read 4 bytes from address "101" on right?
Not exactly, but this will do it:
*pmyInt = *(int *)pmyBytes;
What you''re doing above, is setting the pointer pmyInt to point to the exact memory location that pmyBytes is pointing to (101 that is).
quote:
Now let''s say I want to start reading from address "105" ... how would I do that?
The following should do it:
*pmyInt = *++((int *)pmyBytes);
pmyBytes is a pointer to a byte, but once you typecast it, the compiler treats it as a pointer to an integer. That''s why when you do ++ it increases the address of where pmyBytes is pointing to by 4 (size of integer in windows), and not by 1 (size of byte).
Hope this makes things a bit clearer!
-------------------------------
"Mind your own damn business!!!" - Gladiator
..-=gLaDiAtOr=-..
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement