Hello.
I have a C# application and a native dll written in C++. I have a function called ReadHash() in native dll. I need this function to return an array of bytes. I made a struct called HashRecord in C# and C++. it looks like this
typedef
struct tag_Hash_Record { BYTE HashCode[];} HashRecord, *PHashRecord;
and
public struct HashRecord{
public byte[] HashCodes;}
the ReadHash() function returns HashRecord structure. but when i call this function from c# app, I get a MarshalDirectiveException sayng "Method's type signature is not PInvoke compatible.". anyone knows how to fix this problem thanks.

native struct --> C#
Qiao
Try signatures like these
// C++ side
void YourFunc(BYTE hashCode[]);
// C# side
static extern void YourFunc(byte[] hasCode);
You may have to add a parameter indicating the length of the buffer unless the hash has a well known fixed size.
HairyDan
Change the type of ImagenM to IntPtr.
JosephCooney
geoffacox
Paul Russell
pravej
My struct in C++ is:
float pintura;
float sustrato;
float adherencia;
char* codiErrorAdMalla;
unsigned char * ImagenM;
int alto;
int ancho;
}DatosAdMalla;
and the struct in C# is:
{
public float pintura;
public float sustrato;
public float adherencia;
public string codiErrorAdMalla;
public byte[] ImagenM;
public int alto;
public int ancho;
}
"Method's type signature is not PInvoke compatible.".
what can i do
thanks
Seba85
If you control both the native and managed side it's easier to change the function to return the data via output parameters.