Converting returned IntPtr to Struct or Reference type

  • Thread starter Thread starter Gaz
  • Start date Start date
G

Gaz

Hi all,

I'm using a 3rd party Assembly that contains a method which returns
bitmap data, however the Return value type is IntPtr and I need to
convert it so I can access the Bitmap data:

I'm trying to use a Callback function:

public delegate My_RETURN STATE_CALLBACK(
IntPtr GuiStateCallbackCtx,
BioAPI_GUI_STATE GuiState,
BioAPI_GUI_RESPONSE Response,
BioAPI_GUI_MESSAGE Message,
BioAPI_GUI_PROGRESS Progress,
IntPtr SampleBuffer);

I can use this method and the CallBack function is executed but I'm
stuck as to how to convert the returned Samplebuffer IntPtr into the
GUI_BITMAP structures defined as below:

public class GUI_BITMAP
{
public uint Width;
public uint Height;
public GUI_DATA Bitmap;
}

public class GUI_DATA
{
public uint Length = 0;
public byte[] Data = null;
}

I'm very new to using C# having come from a Delphi background and am
struggling with converting/casting Pointer types to meaningful
structures.

If anyone could give me any help on this it would be much appreciated!

Thanks for your time,

Gareth
 
Gareth,

Have a look at the System.Runtime.InteropServices.Marshal class,
especially its PtrToStructure and Copy methods.



Mattias
 
Back
Top