C + + function prototypes:
BOOL _stdcall Psstartup (HANDLE Hprintps, LPCSTR Lpszdatabasepath, LPCSTR lpszspoolfile);
Lpszspoolfile is the return parameter, which is assigned by the Psstartup and brought back.
The first statement I made in C # was:
[DllImport ("PrintScu.dll", callingconvention = callingconvention.stdcall)]public extern static int Psstartup (INTPTR Hprintps, string lpszdatabasepath, ref string lpszspoolfile);
However, an error occurred during the actual call:
System.accessviolationexception is unhandled message=attempted to read or write protected memory. This is often a indication that other memory is corrupt. Source=mscorlib StackTrace: at System.String.. ctor (sbyte* value) at System.StubHelpers.CSTRMarshaler.ConvertToManaged (IntPtr CStr)
After finding a circle on the internet, I found that this declaration is not possible, you cannot use ref string, and you need to use StringBuilder, and then change to the following declaration, test pass:
[DllImport ("PrintScu.dll", callingconvention = callingconvention.stdcall)]public extern static int Psstartup (INTPTR Hprintps, String lpszdatabasepath, StringBuilder lpszspoolfile);
StackOverflow Post Address
When C # calls C + +, the string returns a parameter with an Access exception error