Aloha-everyone,
I would like to to know how to convert a memory content of an intptr into its equivalent data.
I should be missing the meaning of IntPtr that I think it is a pointer to somewhere in memory, for example a string, I would like to get that string. Is there a method to do that ? Thank you
Aloha-everyone, I would like to to know how to convert a memory content of
Share
Have a look at the
System.Runtime.InteropServices.Marshalclass (hyperlink to MSDN).There’s a
Copymethod that accepts anIntPtrsource and copies characters into achar[]array. It should be easy to convert that into a regularstring. There’s also other methods that interpret the memory content differently; that is, you need to know what type of data you’re expecting at the memory location you’re looking at, and then you need to choose the appropriate overload ofCopy.That being said, an
IntPtris really just a native-size integer (unlike e.g. Int32, which is always 32 bits wide). As such, it’s often used in interop scenarios in places where memory addresses (pointers) are passed around… thus you find the above method in theSystem.Runtime.InteropServicesnamespace.