我從cpp項目創建了一個dll。 從vb項目調用該dll時,應用程序崩潰。 與此錯誤消息:從vb調用C++ dll時出現「new」崩潰
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,並看到飛機墜毀在這一行
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:="?
[email protected]@@[email protected]")> _
Public Function initEngine(ByVal lpString As String) As Boolean
End Function
...
initEngine("C:\1.txt")
正如我寫的 - CAREngine的構造函數爲空 – iRadium
你能展示更多的VB代碼嗎?就像你如何創建'Engine'實例一樣?或者你只是調用'initEngine'成員函數而沒有任何'Engine'實例? –
這是所有的vb代碼。在VB中沒有引擎類 – iRadium