大家好,又见面了,我是你们的朋友全栈君。
InternetOpen:
Initializes an application’s use of the WinINet functions.
HINTERNET InternetOpen(
_In_ LPCTSTR lpszAgent,
_In_ DWORD dwAccessType,
_In_ LPCTSTR lpszProxyName,
_In_ LPCTSTR lpszProxyBypass,
_In_ DWORD dwFlags
);
Remarks
InternetOpen is the first WinINet function called by an application. It tells the Internet DLL to initialize internal data structures and prepare for future calls from the application. When the application finishes using the Internet functions, it should call InternetCloseHandle to free the handle and any associated resources.
InternetOpenUrl:
Opens a resource specified by a complete FTP or HTTP URL.
HINTERNET InternetOpenUrl(
_In_ HINTERNET hInternet,
_In_ LPCTSTR lpszUrl,
_In_ LPCTSTR lpszHeaders,
_In_ DWORD dwHeadersLength,
_In_ DWORD dwFlags,
_In_ DWORD_PTR dwContext
);
InternetReadFile:
Reads data from a handle opened by the InternetOpenUrl, FtpOpenFile, or HttpOpenRequest function.
BOOL InternetReadFile(
_In_ HINTERNET hFile,
_Out_ LPVOID lpBuffer,
_In_ DWORD dwNumberOfBytesToRead,
_Out_ LPDWORD lpdwNumberOfBytesRead
);
#include <windows.h> #include <WinInet.h> #include <iostream> #pragma comment(lib,"wininet.lib") using namespace std; int DownLoader() { DWORD dwByteRead = 0; char szDownBuffer[4096]; memset(szDownBuffer, 0, 4096); BOOL bIntNetReadFile = TRUE; BOOL bWriteFile = TRUE; DWORD dwWritten = 0; HINTERNET hintInternetOpen = InternetOpen("Testing", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); if (!hintInternetOpen) { InternetCloseHandle(hintInternetOpen); return 1; } HINTERNET hintInternetOpenUrl = InternetOpenUrl(hintInternetOpen, "http://w.x.baidu.com/go/mini/2/10100", NULL, 0, INTERNET_FLAG_RELOAD, 0); if (!hintInternetOpenUrl) { InternetCloseHandle(hintInternetOpen); InternetCloseHandle(hintInternetOpenUrl); return 1; } HANDLE hCreateFile = CreateFile("D:\\BaiDu2.exe", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (hCreateFile == INVALID_HANDLE_VALUE) { InternetCloseHandle(hintInternetOpen); InternetCloseHandle(hintInternetOpenUrl); return 1; } while (bIntNetReadFile && bWriteFile) { bIntNetReadFile = InternetReadFile(hintInternetOpenUrl, szDownBuffer, sizeof(szDownBuffer), &dwByteRead); if (!dwByteRead) { break; } bWriteFile = WriteFile(hCreateFile, szDownBuffer, sizeof(szDownBuffer), &dwWritten, NULL); if (!dwWritten) { break; } } InternetCloseHandle(hintInternetOpen); InternetCloseHandle(hintInternetOpenUrl); return 0; } int main() { DownLoader(); system("pause"); return 0; }
D盘下生成了下载的文件:
如果改为动态调用:
#include <windows.h> #include <iostream> #include "dynamicfreetokill.h" using namespace std; int main() { cout << hmWinINetDLL << endl; if (!hmWinINetDLL) { cout << "HMDOULE" << endl; } pfINTERNETCRACKURL pfInternetCrackUrl = (pfINTERNETCRACKURL)GetProcAddress(hmWinINetDLL, "InternetCrackUrlW"); cout << pfInternetCrackUrl << endl; if (!pfInternetCrackUrl) { cout << "InternetCrackUrlW" << endl; } pfINTERNETOPEN pfInternetOpen = (pfINTERNETOPEN)GetProcAddress(hmWinINetDLL, "InternetOpenW"); cout << pfInternetOpen << endl; if (!pfInternetOpen) { cout << "InternetOpenW" << endl; } pfINTERNETCONNECT pfInternetConnect = (pfINTERNETCONNECT)GetProcAddress(hmWinINetDLL, "InternetConnectW"); cout << pfInternetConnect << endl; if (!pfInternetOpen) { cout << "InternetConnectW" << endl; } pfHTTPOPENREQUEST pfHttpOpenRequest = (pfHTTPOPENREQUEST)GetProcAddress(hmWinINetDLL, "HttpOpenRequestW"); cout << pfHttpOpenRequest << endl; if (!pfInternetOpen) { cout << "HttpOpenRequestW" << endl; } pfINTERNETSETOPTION pfInternetSetOption = (pfINTERNETSETOPTION)GetProcAddress(hmWinINetDLL, "InternetSetOptionW"); cout << pfInternetSetOption << endl; if (!pfInternetOpen) { cout << "InternetSetOptionW" << endl; } pfHTTPSENDREQUEST pfHttpSendRequest = (pfHTTPSENDREQUEST)GetProcAddress(hmWinINetDLL, "HttpSendRequestW"); cout << pfHttpSendRequest << endl; if (!pfInternetOpen) { cout << "HttpSendRequestW" << endl; } pfHTTPQUERYINFO pfHttpQueryInfo = (pfHTTPQUERYINFO)GetProcAddress(hmWinINetDLL, "HttpQueryInfoW"); cout << pfHttpQueryInfo << endl; if (!pfInternetOpen) { cout << "HttpQueryInfoW" << endl; } pfINTERNETCLOSEHANDLE pfInternetCloseHandle = (pfINTERNETCLOSEHANDLE)GetProcAddress(hmWinINetDLL, "InternetCloseHandle"); cout << pfInternetCloseHandle << endl; if (!pfInternetOpen) { cout << "InternetCloseHandle" << endl; } pfINTERNETSETFILEPOINTER pfInternetSetFilePointer = (pfINTERNETSETFILEPOINTER)GetProcAddress(hmWinINetDLL, "InternetSetFilePointer"); cout << pfInternetSetFilePointer << endl; if (!pfInternetOpen) { cout << "InternetSetFilePointer" << endl; } pfINTERNETGETLASTRESPONSEINFO pfInternetGetLastResponseInfo = (pfINTERNETGETLASTRESPONSEINFO)GetProcAddress(hmWinINetDLL, "InternetGetLastResponseInfoW"); cout << pfInternetGetLastResponseInfo << endl; if (!pfInternetOpen) { cout << "InternetGetLastResponseInfoW" << endl; } pfINTERNETREADFILE pfInternetReadFile = (pfINTERNETREADFILE)GetProcAddress(hmWinINetDLL, "InternetReadFile"); cout << pfInternetReadFile << endl; if (!pfInternetOpen) { cout << "InternetReadFile" << endl; } FreeLibrary(hmWinINetDLL); system("pause"); return 0; }
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/155120.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...