我用w32编写的dll
extern "C" __declspec (dllexport) int test (int a)
{
return a;
}
在调用的时候出错,请问是什么原因?
HINSTANCE m_hDLL=LoadLibrary("w32dll.dll");
typedef int (CALLBACK* LPTEST)(int);
LPTEST test;
if(m_hDLL!=NULL)
{
test=(LPTEST)GetProcAddress(m_hDLL,"test");
int ok=test(2);
}
extern "C" __declspec (dllexport) int test (int a)
{
return a;
}
在调用的时候出错,请问是什么原因?
HINSTANCE m_hDLL=LoadLibrary("w32dll.dll");
typedef int (CALLBACK* LPTEST)(int);
LPTEST test;
if(m_hDLL!=NULL)
{
test=(LPTEST)GetProcAddress(m_hDLL,"test");
int ok=test(2);
}
extern "C" __declspec (dllexport) int test (int a)
{
int ret =a;
return ret ;
}试试。
对了你没说“调用时出错”是错在哪儿了?
时,提示:出错信息
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
convention
谢谢帮忙看看!
不知为啥代参数后就出错了???
请帮忙看看看,非常感谢!!!
我还是自己解决吧!!
我查阅了以前的贴子,解决了!
由参数不用CALLBACK
c的默认调用约定是_cdecl,你声明函数时用上stdcall:extern "C" __declspec (dllexport) int __stdcall test (int a)
{
return a;
}注意在函数定义和声明两个地方都加上__stdcall再试试。