我试图控制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