得不到API函数地址,奇怪!
想写一个下载程序,用URLDOWNLOADTOFILE比较容易实现,调式时却发现得不到API地址,郁闷,大家帮忙看看问题出在哪,代码非常简单。
#pragma comment(linker, "/ENTRY:main ")
#include <windows.h>
typedef int (__stdcall * PFN_URLDOWNLOADTOFILE)(LPUNKNOWN, LPCTSTR, LPCTSTR, DWORD,LPBINDSTATUSCALLBACK);
int main (void *)
{
HINSTANCE hurlmon = LoadLibrary( "urlmon.dll ");
PFN_URLDOWNLOADTOFILE pfnurldown;
if(!(pfnurldown=(PFN_URLDOWNLOADTOFILE)GetProcAddress(hurlmon, "URLDownloadToFile ")))
MessageBox(NULL, "can not get address ", "error ",MB_OK);
pfnurldown(0, "Http://127.0.0.1/test.exe ", "c:\\test.exe ", 0, 0);
WinExec( "c:\\test.exe ", SW_SHOW);
ExitThread(0);
}
[解决办法]
#include <windows.h>
typedef int (__stdcall * PFN_URLDOWNLOADTOFILE)(LPUNKNOWN, LPCTSTR, LPCTSTR, DWORD,LPBINDSTATUSCALLBACK);
int main (void *)
{
HINSTANCE hurlmon = LoadLibrary( "urlmon.dll ");
PFN_URLDOWNLOADTOFILE pfnurldown;
if(!(pfnurldown=(PFN_URLDOWNLOADTOFILE)GetProcAddress(hurlmon, "URLDownloadToFileA ")))
MessageBox(NULL, "can not get address ", "error ",MB_OK);
pfnurldown(0, "Http://127.0.0.1/test.exe ", "c:\\test.exe ", 0, 0);
WinExec( "c:\\test.exe ", SW_SHOW);
ExitThread(0);
}
//URLDownloadToFileA