1

I'm trying to control a motor via a device called a Motor-Bee, and using C++.

This is the code I'm using :

#include <iostream.h>
#include <mt.h>
#include <windows.h>
#pragma hdrstop


int _tmain(int argc, _TCHAR* argv[])
{

HINSTANCE HStpDll; // declaration of variable to hold the handle to the dll
HStpDll = LoadLibrary( _T("mtb.dll")); // load the dll into memory and return handle


Type_InitMotoBee InitMotoBee;
Type_SetMotors SetMotors;

InitMotoBee = (Type_InitMotoBee)GetProcAddress( HStpDll, " InitMotoBee");

SetMotors =(Type_SetMotors)GetProcAddress(HStpDll, " SetMotors");


InitMotoBee();
    SetMotors(0, 50, 0, 0, 0, 0, 0, 0, 0);

return 0;
}

mt.h and mtb.dll are files which come with the device.

When I try to run the program, all I get is a box pop up saying:

"Project2.exe raised exception classEAccessViolation with message 'Access violation at address 00000000. Read of address 00000000'. Process stopped. Use step or Run to continue."

A PDF manual with info about C++ functions can be found here.

Could anyone tell me what I'm doing wrong? Or, course how to solve it if possible.

4

1 回答 1

4

调用中的函数名称前有空格GetProcAddress(),这似乎非常错误。

此外,您没有在使用返回的指针之前检查它们的有效性,这就是查找失败时它崩溃的原因。

于 2013-08-16T13:22:42.987 回答