求助:我的 dll 中的数组调用总是出错,请帮我看看啊,谢谢!

lshlsh2008 2016-10-07 09:32:01
请教:
// iTween.cpp : 定义 DLL 应用程序的导出函数。

#ifdef ITWEEN_EXPORTS
#define DLL_API __declspec(dllexport)
#else
#define DLL_API __declspec(dllimport)
#endif

int groupID = 0xC154;
char dogOnlyId[30] = "314A990D1A6E4D0F";


extern "C" DLL_API int ReadGroupID()
{
return groupID;
}

extern "C" DLL_API void ReadDogOnlyId(char *getDogOnlyId)
{
getDogOnlyId = dogOnlyId;
}

编译为 iTween.dll


// Test1.cpp : 定义 DLL 应用程序的导出函数。
#ifdef TEST1_EXPORTS
#define DLL_API __declspec(dllexport)
#else
#define DLL_API __declspec(dllimport)
#endif


int groupID = 0xC153; //分组号
char dogOnlyId[64] = "314A990D1A60F";


extern "C" DLL_API int readNumber()
{
HINSTANCE hDllInst = LoadLibrary("iTween.dll");

typedef int (WINAPI *FunReadGroupID)();

typedef void (WINAPI *FunReadDogOnlyId)(char *);


FunReadGroupID MyReadGroupID = NULL; //函数别名
FunReadDogOnlyId MyReadDogOnlyId = NULL;

MyReadGroupID = (FunReadGroupID)GetProcAddress (hDllInst, "ReadGroupID");

MyReadDogOnlyId = (FunReadDogOnlyId)GetProcAddress (hDllInst, "ReadDogOnlyId");

if(MyReadGroupID)
{
groupID = MyReadGroupID();
}

if(MyReadDogOnlyId)
{
MyReadDogOnlyId(dogOnlyId);
}


FreeLibrary(hDllInst);
}


编译为 Test1.dll


现在情况是,我在别的程序调用 Test1.dll 的 readNumber()

当执行 MyReadDogOnlyId(dogOnlyId);

就出现错误。

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.
This is usually of calling a function declared with one calling convention with a function
pointer declared with a different calling convention

我哪里错了啊?

谢谢!
...全文
62 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lshlsh2008 2016-10-07
  • 打赏
  • 举报
回复
太感谢了,可以了!
paschen 版主 2016-10-07
  • 打赏
  • 举报
回复
paschen 版主 2016-10-07
  • 打赏
  • 举报
回复
调用约定不对....

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧