为何自己写的dll调用函数会出错,详见内容
// mydll.h文件
#ifdef __cplusplus
#define EXPORT extern "C" __declspec (dllexport)
#else
#define EXPORT __declspec (dllexport)
#endif
EXPORT int FA(int a);
// mydll.cpp文件
#include "stdafx.h"
#include "mydll.h"
EXPORT int FA(int a)
{
return a*a;
}
// 测试程序部分代码
typedef int (WINAPI *PFA)(int);
void getResult()
{
int a;
HINSTANCE hLibrary;
PFA FA;
hLibrary=LoadLibrary(TEXT("Testdll.dll"));
if(hLibrary != NULL)
{
FA = (GGG)GetProcAddress(hLibrary, "FA");
a = FA(10);
FreeLibrary(hLibrary);
}
}
当程序执行时提示如下错误信息,经检查是a = FA(10)语句出错,不知道为何?
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
编程环境:win7 64位,Visual Studio 2010.