AccessViolationException from c# when calling a function defined in a c++ library
We have a C++ library where some methods are defined and exported and are being used by our .NET (V 3.5) application. In the c++ library, a function is defined as below
int DLLEXPORT RunAnalysis(long *time, long hand开发者_如何学JAVAle, int *Status)
{
// some code...
}
in .Net assembly
Declaration
[DllImport("wt3145.dll")]
private static extern int RunAnalysis(ref long Time, long Handle, ref int status);
Usage
// Some work..
ErrorCode = RunAnalysis(Time, ref Handle, ref Status);
// Some other work
every time this call is encountered an AccesViolationException occures. it gets solved only when i pass the second parameter with ref
keyword although it is not being passed using a pointer.
Any specific reason for this behavior???try
[DllImport("wt3145.dll")]
private static extern int RunAnalysis(ref int Time, int Handle, ref int status);
long
in C++ is not the same as long
in C#.
精彩评论