I have a DLL written in C that I must use in my C# application.
The C declarations for the two functions in question are as follows:
Code:
IMGSTRUCT *LoadImg(const char *filename)
int UseImg(IMGSTRUCT *img,int flag)
The structures are defined as follows in C.
typedef struct tagBITMAPINFOHEADER{
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER, FAR *LPBITMAPINFOHEADER, *PBITMAPINFOHEADER;
typedef struct {
LPBITMAPINFOHEADER bi; // bitmap info
unsigned char * imgBits; // image content
}
IMGSTRUCT;
I know how to marshal the BITMAPINFOHEADER structure.
Code:
[StructLayout(LayoutKind.Sequential)]
public struct BITMAPINFOHEADER
{
public uint biSize;
public int biWidth;
public int biHeight;
public ushort biPlanes;
public ushort biBitCount;
public uint biCompression;
public uint biSizeImage;
public int biXPelsPerMeter;
public int biYPelsPerMeter;
public uint biClrUsed;
public uint biClrImportant;
public void Init()
{
biSize = (uint)Marshal.SizeOf(this);
}
}
How do I marshal the IMGSTRUCT structure?
It has a member of BITMAPINFOHEADER pointer and a pointer to an array of image data.
Then how would the P/Invoke look for both LoadImg() and UseImg()?