请教个问题,C#调用c++ dll报了个异常:
An unhandled exception of type 'System.AccessViolationException' occurred in AlgorithmLib.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
C# code:
[DllImport(CSAlgorithmPath, EntryPoint = "?GetVersion@CSAlgorithm@algo@@QAEHPAD@Z", CallingConvention = CallingConvention.Cdecl, CharSet=CharSet.Auto, SetLastError=true)]
public static extern int GetVersion(StringBuilder pVersion);
C++ code:
int CSAlgorithm:: GetVersion(char* pVersion)
{
boost::unique_lock<boost::recursive_mutex> lock(*m_mutex);
return m_algorithm->GetVersion(pVersion);
}
之前没有下划线的锁,没有问题,现在有锁了,请教应该怎么办?不能改C++的代码。
Thanks!
1、CallingConvention = CallingConvention.Cdecl, CharSet=CharSet.Auto 可能设置错误。
2、m_mutex 没有初始化或者已经释放。
最后也没解决,用托管c++写了个wrapper。