个人愚见:首先要知道该动态库引出函数,然后调用就是了,下面是一个动态调用的例子:
//动态调用dll
//无参数情况
HINSTANCE dd;
AnsiString dllfile=ExtractFilePath(Application->ExeName)+"CXmlProcess.dll";
int _stdcall (*ddd)(void);
dd=LoadLibrary(dllfile);
ddd=GetProcAddress(dd,"test"
;
Caption=IntToStr(ddd());
FreeLibrary(dd);
//有参数调用,有int 返回值
HINSTANCE hinstance;
AnsiString a=ExtractFilePath(Application->ExeName)+"mydll.dll";
int (*nsetup)(HWND,int);//有两个参数
hinstance=LoadLibrary(WideString(a));
if(hinstance)
{
nsetup=(int(*)(HWND,int))::GetProcAddress(hinstance,"nsetup"
;//带参数指定函数入口
int i=nsetup(Application->Handle,5);//带入实参
}
FreeLibrary(hinstance);
//有参数调用,有char * 指针型返回值
HINSTANCE hinstance;//定义一个实例变量
char *r;//接收返回的指针
AnsiString s="I love you 我爱你";//参数1
AnsiString dllfile=ExtractFilePath(Application->ExeName)+"CXmlProcess.dll";
char * (*ToUTF_8)(char *,int );//定义指向动态库的函数名*ToUTF_8变量,有两个参数,返回值为char * 指针型
hinstance=LoadLibrary(WideString(dllfile));//读入动态库
if(hinstance)
{
ToUTF_8=(char*(*)(char *,int))::GetProcAddress(hinstance,"translateCharToUTF_8"
;//带参数指定函数入口地址
if(ToUTF_8)
{
r=ToUTF_8(s.c_str(),s.Length());//带入实参
TntMemo1->Clear();
TntMemo1->Lines->Add(r);
}
FreeLibrary(hinstance);
}