How get value from IntPtr that hold someone value in memory using Marshal

  • Thread starter Thread starter Pawel
  • Start date Start date
P

Pawel

Hi,
How to get i value (in my case compressed with gzip data ) from IntPtr that
hold this value in memory in known adress.

Declatarion:

[DllImport("clamqa.dll", CharSet=CharSet.Ansi, EntryPoint="CLMQGet")]
public static extern int CLMQGet_ZSF( ref IntPtr bufer, int buffer_len);


My example below:

IntPtr myBuff = IntPtr.Zero;
GetMemCmpressed( ref myBuff , out TrueMessLength );
byte[] dest = new byte[TrueMessLength];
Marshal.Copy(myBuff, dest, 0, TrueMessLength); // here is exception calling
why ? NullReferenceExeption ?
// myBuffer pointer is greather than 0

Thanks for any help.
Regards,
Pawel
 
See if Marshal.PtrToStructure will do what you need.

You may need to look at the unmanaged definition of what this buffer
should look like and define a managed struct with identical layout so
that this function will have a place to put the memory.
 
Back
Top