动态调用dll函数的方法
动态调用dll函数的方法
// 声明typedef HRESULT (__stdcall *SHGETFOLDERPATHPROC)(
HWND hwndOwner,
int nFolder,
HANDLE hToken,
DWORD dwFlags,
LPTSTR pszPath
);
// 调用
SHGETFOLDERPATHPROC g_pfnSHGetFolderPath=NULL;
HMODULE hModSHFolder = LoadLibrary("shfolder.dll");
if ( hModSHFolder != NULL )
{
(*(FARPROC*)&g_pfnSHGetFolderPath = GetProcAddress(hModSHFolder,"SHGetFolderPathA"));
if (!g_pfnSHGetFolderPath) {
FreeLibrary(hModSHFolder);
TRACE("can't get SHGetFolderPathA Pointer./n");
return 1;
}
}
else
{
g_pfnSHGetFolderPath = NULL;
TRACE("can't load shfolder.dll");
return 1;
}
if(g_pfnSHGetFolderPath(NULL,CSIDL_PROGRAM_FILES|CSIDL_FLAG_CREATE,NULL,SHGFP_TYPE_CURRENT,Buffer)==E_FAIL)
{
TRACE("Can't Find Program File folder.");
FreeLibrary(hModSHFolder);
return 1;
}
FreeLibrary(hModSHFolder);