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

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
 
N

Nick Hertl

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top