DLL装载成功,却找不到所需函数,请教了!
yqcxm 2003-11-12 10:45:23 DLL文件:
#include <windows.h>
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
extern _declspec(dllexport)double mytest();
double mytest()
{
return 100.0;
}
DLL头文件:
#ifndef MyDllH
#define MyDllH
extern "C" _declspec(dllexport) double mytest();
#endif
外部程序调用代码:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HINSTANCE h;
FARPROC cv;
h=LoadLibrary("mydll");
if(h)
{
MessageBox(NULL,"成功装载MYDLL","成功",0);
cv=(FARPROC)GetProcAddress(h,"mytest");
if(cv)
{
MessageBox(NULL,"成功找到函数","成功",0);
double aa=cv();
Label1->Caption =AnsiString(aa);
}
else MessageBox(NULL,"找不到函数","失败",0);
FreeLibrary (h);
}
}