【发布时间】:2014-01-29 14:17:41
【问题描述】:
我正在从一个 cpp 项目创建一个 dll。 从 vb 项目调用此 dll 时,应用程序崩溃。 带有此错误消息:
An unhandled exception of type 'System.AccessViolationException' occurred in...
Additional information: Attempted to read or write protected memory. This is often
an indication that other memory is corrupt.
我可以调试dll,看到crash就在这一行
carEngine = new CAREngine ();
CAREngine 构造函数为空。什么可能导致此崩溃?
代码如下:
C++ .h 文件:
#include "CarEngine.h"
class Engine
{
public:
bool __declspec(dllexport) initEngine(LPCTSTR DBfileName);
private:
CAREngine* carEngine;
};
C++ .cpp 文件:
bool Engine::initEngine(LPCTSTR DBfileName)
{
logText("Engine Loading start");
carEngine = new CAREngine (); //<- Crash is here
...
}
VB:
<DllImport("myengine.dll", EntryPoint:="?
initEngine@Engine@@QAE_NPBD@Z")> _
Public Function initEngine(ByVal lpString As String) As Boolean
End Function
...
initEngine("C:\1.txt")
【问题讨论】:
-
正如我所写 - CAREngine 构造函数是空的
-
你能展示更多的VB代码吗?就像您如何创建
Engine实例一样?还是只调用initEngine成员函数而不使用任何Engine实例? -
这是所有的vb代码。 VB中没有引擎类