0
votes

DLLENTRY int CCON mfScan (int, int, int, char *, int *);

[DllImport("mflib.dll")]
public static extern int mfScan(int mode, int font, int timeout, string ret_codeline, int ret_maxchars);

I get the below error with this code. It points to test. What can i do ?

 string test = string.Empty;
 int retval = mfScan(32, 2, 5000, test, 100);

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

2

2 Answers

3
votes

Try with this:

[DllImport("mflib.dll")]
public static extern int mfScan(int mode, int font, int timeout, StringBuilder ret_codeline, out int ret_maxchars);

Please note the StringBuilder instead of string, additionally to the out int ret_maxchars. Then ensure the calling convention is correct.

3
votes

Should be out int ret_maxchars.

You should also consider adding CharSet to the DllImport.