VS2015 应用程序在调用具有委托C++函数时崩溃
VS2015 application crashes when calling C++ function with delegates
我正在使用ABBYY的FineReader引擎,当尝试初始化时,我的应用程序崩溃了(在调试时)。如果我运行.exe它工作正常。
声明:
<DllImport("kernel32.dll")>
Private Shared Function LoadLibrary(dllToLoad As String) As IntPtr
End Function
<DllImport("kernel32.dll")>
Private Shared Function GetProcAddress(hModule As IntPtr, procedureName As String) As IntPtr
End Function
<DllImport("kernel32.dll")>
Private Shared Function FreeLibrary(hModule As IntPtr) As Boolean
End Function
' FREngine.dll functions
<UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet:=CharSet.Unicode)>
Private Delegate Function GetEngineObject(devSN As String, reserved1 As String, reserved2 As String, ByRef engine As FREngine.IEngine) As Integer
<UnmanagedFunctionPointer(CallingConvention.StdCall)>
Private Delegate Function DeinitializeEngine() As Integer
<UnmanagedFunctionPointer(CallingConvention.StdCall)>
Private Delegate Function DllCanUnloadNow() As Integer
并初始化:
' Load the FREngine.dll library
dllHandle = LoadLibrary(enginePath)
Try
If dllHandle = IntPtr.Zero Then
Throw New Exception("Can't load " + enginePath)
End If
Dim getEngineObjectPtr As IntPtr = GetProcAddress(dllHandle, "GetEngineObject")
If getEngineObjectPtr = IntPtr.Zero Then
Throw New Exception("Can't find GetEngineObject function")
End If
Dim deinitializeEnginePtr As IntPtr = GetProcAddress(dllHandle, "DeinitializeEngine")
If deinitializeEnginePtr = IntPtr.Zero Then
Throw New Exception("Can't find DeinitializeEngine function")
End If
Dim dllCanUnloadNowPtr As IntPtr = GetProcAddress(dllHandle, "DllCanUnloadNow")
If dllCanUnloadNowPtr = IntPtr.Zero Then
Throw New Exception("Can't find DllCanUnloadNow function")
End If
' Convert pointers to delegates
_getEngineObject = DirectCast(Marshal.GetDelegateForFunctionPointer(getEngineObjectPtr, GetType(GetEngineObject)), GetEngineObject)
_deinitializeEngine = DirectCast(Marshal.GetDelegateForFunctionPointer(deinitializeEnginePtr, GetType(DeinitializeEngine)), DeinitializeEngine)
_dllCanUnloadNow = DirectCast(Marshal.GetDelegateForFunctionPointer(dllCanUnloadNowPtr, GetType(DllCanUnloadNow)), DllCanUnloadNow)
' Call the GetEngineObject function
Dim hresult As Integer = _getEngineObject(developerSN, Nothing, Nothing, m_engine)
最后一行是导致崩溃的那一行(无错误或输出)。相同的代码在VS2010中工作正常,但在VS2015中则不然。我在这里错过了什么?
它崩溃的原因是因为你使用非开发人员许可证在Visual Studio中调试ABBYY,不幸的是,它崩溃了,没有提供有意义的异常,他们的支持网站上没有关于这方面的信息。
确保在调试时使用开发人员许可证,如果通过 exe 运行运行时许可证,请确保使用运行时许可证。
在VS2010中查看项目的项目属性,并在VS2015中应用相同的设置,检查包含库路径并确保DLL位于正确的位置
相关文章:
- "error: no matching function for call to"构造函数错误
- 什么时候调用组成单元对象的析构函数
- 继承函数的重载解析
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- C++模板来检查友元函数的存在
- 递归函数计算序列中的平方和(并输出过程)
- 对RValue对象调用的LValue ref限定成员函数
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 为什么使用 "this" 指针调用派生成员函数?
- 将对象数组的引用传递给函数
- 函数调用中参数的顺序重要吗
- 函数向量_指针有不同的原型,我可以构建一个吗
- 使用不带参数的函数访问结构元素
- 代码在main()中运行,但在函数中出现错误
- 内置函数可查看CPP中的成员变量
- 如何获取std::result_of函数的返回类型
- 如何在c++中为模板函数实例创建快捷方式
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗