我試圖控制MotorBee用C++, 的問題是,我使用的是與MotorBee「mtb.dll」MotorBee DLL和C++,內存訪問衝突
我試圖加載進來一個dll文件從DLL到我的C++程序的功能如下:
#include "stdafx.h"
#include <iostream>
#include "mt.h"
#include "windows.h"
using namespace std;
HINSTANCE BeeHandle= LoadLibrary((LPCWSTR) "mtb.dll");
Type_InitMotoBee InitMotoBee;
Type_SetMotors SetMotors;
Type_Digital_IO Digital_IO;
int main() {
InitMotoBee = (Type_InitMotoBee)GetProcAddress(BeeHandle, " InitMotoBee");
SetMotors =(Type_SetMotors)GetProcAddress(BeeHandle, " SetMotors");
Digital_IO =(Type_Digital_IO)GetProcAddress(BeeHandle, " Digital_IO "); InitMotoBee();
SetMotors(0, 50, 0, 0, 0, 0, 0, 0, 0);
system("pause");
return 0;
}
我收到一個錯誤說,我想讀存儲器, 0x00000000地址,當我嘗試清點BeeHandle它顯示爲0x0地址(嘗試檢查處理值) 樣本錯誤:
First-chance exception at 0x00000000 in 111111.exe: 0xC0000005: Access violation reading location 0x00000000.
First-chance exception at 0x6148f2b4 in 111111.exe: 0xC0000005: Access violation reading location 0x00000000.
First-chance exception at 0x6148f2b4 in 111111.exe: 0xC0000005: Access violation reading location 0x00000000.
First-chance exception at 0x6148f2b4 in 111111.exe: 0xC0000005: Access violation reading location 0x00000000.
First-chance exception at 0x6148f2b4 in 111111.exe: 0xC0000005: Access violation reading location 0x00000000.
感謝你的幫助,
執行'GetProcAddress的()'調用成功嗎?我對此表示懷疑,因爲用於函數名稱的每個字符串文字都有空格。 – hmjd 2013-04-09 13:01:06
如果'BeeHandle'爲'0',表示DLL未成功加載。它與你的應用程序在同一個文件夾中嗎? – 2013-04-09 13:02:06
@hmjd正是..「訪問衝突讀取位置0x00000000」表示SetMotors爲0.錯誤處理是件好事。 – stijn 2013-04-09 13:03:06