gpt4 book ai didi

c++ - Motorbee 代码 C++

转载 作者:行者123 更新时间:2023-11-30 01:57:45 25 4
gpt4 key购买 nike

我正在尝试通过一个名为 Motor-Bee 的设备来控制电机,并使用 C++。

这是我正在使用的代码:

#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 和 mtb.dll 是设备自带的文件。

当我尝试运行该程序时,我得到的只是弹出一个框,上面写着:

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

包含有关 C++ 函数信息的 PDF 手册可以 be found here .

谁能告诉我我做错了什么?或者,当然如果可能的话如何解决它。

最佳答案

GetProcAddress() 调用中的函数名前有空格,这似乎很不对。

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

关于c++ - Motorbee 代码 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18274281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com