bool WINAPI (*CompressFile)();//压缩
bool WINAPI (*ExtractFileToDir)();//解压
MyHandle = LoadLibrary ("ZIP.dll");
if (MyHandle==NULL) return ;
(FARPROC)CompressFile = GetProcAddress(MyHandle,"CompressFile");
if (CompressFile()==true)
{//成功
Application->MessageBoxA("压缩调用成功","提示",0+64);
}
Else
{//失败
Application->MessageBoxA("压缩调用失败","提示",0+48);
}
MyHandle=0;两个问题:
1、 bool WINAPI (*CompressFile)();// 编译的时候
会有错误 error C2059: syntax error : '('
但把WINAPI去掉就正常了
2、(FARPROC)CompressFile = GetProcAddress(MyHandle,"CompressFile");
会出现错误C2440: '=' : cannot convert from 'int (__stdcall *)(void)' to 'int'
bool WINAPI (*ExtractFileToDir)();//解压
MyHandle = LoadLibrary ("ZIP.dll");
if (MyHandle==NULL) return ;
(FARPROC)CompressFile = GetProcAddress(MyHandle,"CompressFile");
if (CompressFile()==true)
{//成功
Application->MessageBoxA("压缩调用成功","提示",0+64);
}
Else
{//失败
Application->MessageBoxA("压缩调用失败","提示",0+48);
}
MyHandle=0;两个问题:
1、 bool WINAPI (*CompressFile)();// 编译的时候
会有错误 error C2059: syntax error : '('
但把WINAPI去掉就正常了
2、(FARPROC)CompressFile = GetProcAddress(MyHandle,"CompressFile");
会出现错误C2440: '=' : cannot convert from 'int (__stdcall *)(void)' to 'int'
typedef bool WINAPI *CompressFileFun)();
第二个还是一样……MSDN里 FARPROC GetProcAddress(
HMODULE hModule, // handle to DLL module
LPCSTR lpProcName // name of function
);照道理 应该是把前面的CompressFile强制转换成FARPROC应该就能顺利接收了
总是会出现不匹配这样强制转换就可以通过编译
(bool (__stdcall *)(void))(GetProcAddress(MyHandle,"CompressFile"));但这样的话 下面调用CompressFile函数就会出问题 CompressFile永远也是FLASE
但是下面的CompressFile()还是调用不成功CompressFile应该是在ZIP.DLL里面包含的函数……
不成功是因爲兩者類型不同
FARPROC可能被定義為:
typedef INT_PTR (FAR WINAPI *FARPROC)();
typedef int (FAR WINAPI *FARPROC)();
typedef int (CALLBACK *FARPROC)();
但是其指向函數的返回值都不是bool
你可以嘗試用
BOOL (WINAPI *CompressFile)();
CompressFile = (FARPROC)GetProcAddress(MyHandle,"CompressFile");