首页 新闻 会员 周边

C# call C++ dll throw AccessViolationException

0
悬赏园豆:50 [已解决问题] 解决于 2014-12-08 16:05

请教个问题,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!

abang的主页 abang | 初学一级 | 园豆:157
提问于:2014-11-28 14:28
< >
分享
最佳答案
0

1、CallingConvention = CallingConvention.Cdecl, CharSet=CharSet.Auto 可能设置错误。

2、m_mutex 没有初始化或者已经释放。

收获园豆:50
Launcher | 高人七级 |园豆:45045 | 2014-11-28 14:54

最后也没解决,用托管c++写了个wrapper。

abang | 园豆:157 (初学一级) | 2014-12-08 16:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册