我正在尝试使用 C++ 对 motorbee 进行编程
当我运行代码时,出现以下错误:
运行时检查失败 #0 - ESP 的值未在函数调用中正确保存。这通常是调用使用一种调用约定声明的函数和使用另一种调用约定声明的函数指针的结果。
这是我的代码。
#include "stdafx.h"
#include <iostream>
#include "windows.h"
#include "mt.h"
using namespace std;
HINSTANCE BeeHandle= LoadLibrary("mtb.dll");
Type_InitMotoBee InitMotoBee;
Type_SetMotors SetMotors;
Type_Digital_IO Digital_IO;
void 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);
}
原文由 user1322682 发布,翻译遵循 CC BY-SA 4.0 许可协议
您的
typedef
函数指针需要与您正在使用的库的 调用约定 相匹配。例如,如果InitMotoBee
使用cdecl
您的typedef
将如下所示:SetMotors
函数需要参数,所以调用约定也需要正确设置(这可能是应用程序失败的地方)。