一个关于DLL函数调用的问题
刘爱贵 博客专家认证 2002-04-26 09:27:35 我在DLL定义了一个函数
int CFirstDLLApp::Add_xy(int x, int y)
{
return(x+y);
}
可是在外部调用时总出错,不知道为什么?请大家帮忙!THANKS!
HINSTANCE handlerDLL=NULL;
typedef int(*ADDFUNC)(int x,int y);
ADDFUNC AddFunc;
if(handlerDLL==NULL)
handlerDLL=LoadLibrary("E:\\VC_Study\\FirstDLL\\Debug\\FirstDLL.dll");
if(handlerDLL==NULL)
MessageBox("Cannot Open the DLL");
else
MessageBox("DLL already Loaded!");
AddFunc=(ADDFUNC)GetProcAddress(handlerDLL,"Add_xy");
if(AddFunc)
{
int Result=(*AddFunc)(100,100);
char CBuf[20];
sprintf(CBuf,"100+100=%d",Result);
}
else
MessageBox("Cannot find Function");
FreeLibrary(handlerDLL);