[RESOLVED] dll returns C structure with dynamic arrays, how to get data in c# ???
Hello
I have a DLL written in C and I am struggling with using the functions that return a structure in C#.
C Code that compiles into dll
Code:
typedef struct
{
unsigned int Height; //!< Height of the image in pixels.
unsigned int Width; //!< Width of the image in pixels.
unsgined short ***Pixels;
} IMAGE;
//! Creates and initializes image structure and returns pointer to new image
__declspec(dllexport) IMAGE CreateImage(unsigned int aHeight, unsigned int aWidth);
I need to use this function in C#, this is what i tried:
Code:
public struct IMAGE
{
int Height;
int Width;
short[,,] Pixels;
}
[DLLImport("IMAGE.dll")]
public static extern IMAGE CreateImage(int aHeight, int aWidth);
But when I call
Code:
IMAGE image = new IMAGE();
image = CreateImage(100,100);
I get the error: Method's type signature is not PInvoke compatible
Other functions that return plain integers work just fine. Someone please explain how I can use a structure created by DLL.
Thanks
Re: dll returns C structure with dynamic arrays, how to get data in c# ???
Solved it .....
Code:
public struct IMAGE
{
public Int32 Height;
public Int32 Width;
public IntPtr Pixels;
}
[DllImport("Image.dll")]
public static extern IMAGE CreateImage(Uint32 Height, Uint32 Width);
after calling the CreateImage function I can use Marshal.ReadIntPrt(Pixels) and Marshal.ReadInt16(IntPtr) to get the data :).