I have a problem including a DLL (written in C) in my C # project, and I hope you can help me. In my research, I found DLLImport, but I'm not sure which types of C variables are converted to ...
The C method from the DLL I want to import is as follows:
int lou_translateString (
const char * tableList,
const widechar * inbuf,
int *inlen,
widechar *outbuf,
int *outlen,
char *typeform,
char *spacing,
int mode);
This is the DLLImport I tried:
[DllImport("liblouis-2.dll", EntryPoint = "lou_translateString", CharSet = CharSet.Ansi, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.LPStr)]
public static extern int translate([MarshalAs(UnmanagedType.LPStr)]
String tableList,
String inbuf,
int inlen,
String outbuf,
int outlen,
String typeform,
String spacing,
int mode);
But when I try to call a method, I get:
MarshallDirectiveException Cannot marshal "return value": invalid combination of managed / unmanaged types (Int32 / UInt32 must be mated to I4 or U4)
Can anyone help with an exception? I am sure that this is due to the types of parameters in the method, but I do not know how to declare them correctly. Any help would be appreciated!
Thanks in advance Alex
Added shorted documentation to clarify
16- Unicode inbuf 16- outbuf.
tableList .
, * inlen * outlen . , , . , .
typeform , , .. , * inbuf. , * outlen. typeform . : 0 plain-text; 1 ; 2 ; 4 ; 8 . . NULL, . , NULL, 8 , outbuf, , 7, 8 , .
. , , * inbuf. NULL, .
mode , .
1, 0, .
, Main:
StringBuilder outbuf = new StringBuilder("Test", 30);
int inlength = 100;
int louint = 0;
int outlength = 100;
String inbuf = "test";
louint = lou_translateString("de-de-g1.ctb", inbuf, inlen: ref inlength, outbuf: outbuf, outlen: ref outlength, typeform: null, spacing: null, mode: 8);
. , ? - outbuf, StringBuilder, String (outbuf.Replace())?