0

my c# application calls a c++ function of an external DLL using dll import tag:

 [DllImport("UserAuthentication.dll")]
    private static extern int Validate(string pScrambeled, string szReadable, int flToUpper, string pstrErr);

int WINAPI ValidateAMOSBS(TCHAR *pScrambeled, TCHAR* szReadable, int flToUpper, TCHAR *pstrErr)

Only on one server, and when it is called by an ASP.NET application hosted on IIS, it thrown System.AccessViolationException. We try to change X86, X64 compilation and to reinstall VC++ redistributable without success. Do you have any suggestions?

Thanks,

Davide

riQQ
  • 9,878
  • 7
  • 49
  • 66
  • Possible duplicate of [How to handle AccessViolationException](https://stackoverflow.com/questions/3469368/how-to-handle-accessviolationexception) – Nisarg Shah Aug 09 '18 at 10:40

1 Answers1

1

I do not know how your function ValidateAMOSBS works in details. If, for example last argument TCHAR is an allocated buffer for error message then in import you should use StringBuilder type:

[DllImport("UserAuthentication.dll", CallingConvention = CallingConvention.Cdecl)]
    private static extern int Validate(string pScrambeled, string szReadable, int flToUpper, StringBuilder pstrErr);

and you should allocate buffer for error message before you call Validate function:

StringBuilder pstrErr= new StringBuilder(1000);

Same story is with other TCHAR parameters (if necessary).