DllImport, function argument problems
-
Hi there. I want to import a function of a simple C written DLL from within a C# project. Not that difficult... actually. But I keep getting exceptions. I spent hours for searching on the internet for articles that may help me but didn't find anything that helped me to solve my problem. This is the C code out of the header: [code]typedef struct tagHuffmanObj { int has_incomplete; int incomplete_node; char incomplete_byte; }HuffmanObj; void Compress(char *dest, const char *src, int *dest_size, int *src_size); void Decompress(char *dest, const char *src, int *dest_size, int *src_size, HuffmanObj *obj);[/code] Q1: What's the correct declaration for importing the functions? I tried different things on this, none of it worked. I keep getting NullReference exceptions but I don't know what exactly that means. Some time ago (1+ year) I read that NullReference expeptions come up upon passing wrong arguments to the function. The function in the dll is exactly compiled as given in the header, I recompiled the DLL since it's open source. public static extern void Compress(ref byte[] dest, ref byte[] source, ref int destSize, ref int srcSize); for example. I mean.. if C doesn't care about datatypes, the function would simlpy read the byte code given by dest/source with the given lengths. And I just pass it a byte array with the ascii codes. Q2: Is it correct, that the C# struct for HuffmanObj is just 2 int variables and a byte variable in the same order? Just to be sure.. I'm kinda confused on how to import the functions properly.