HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType, LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags) { appinfo_t *lpwai = NULL; lpwai = alloc_object(NULL, &APPINFOVtbl, sizeof(appinfo_t)); if (!lpwai) { SetLastError(ERROR_OUTOFMEMORY); return NULL; } lpwai->hdr.htype = WH_HINIT; lpwai->hdr.dwFlags = dwFlags; lpwai->accessType = dwAccessType; lpwai->proxyUsername = NULL; lpwai->proxyPassword = NULL; lpwai->agent = heap_strdupW(lpszAgent); if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG) INTERNET_ConfigureProxy( lpwai ); else lpwai->proxy = heap_strdupW(lpszProxy); lpwai->proxyBypass = heap_strdupW(lpszProxyBypass); TRACE("returning %p\n", lpwai); return lpwai->hdr.hInternet; //这里在alloc_object做的。 //这里看是返回的索引,但我实际检测的时候,返回数组的地址,而不是索引,其实2种相同。 }
NTERNETAPI HINTERNET WINAPI InternetOpenA( IN LPCSTR lpszAgent, IN DWORD dwAccessType, IN LPCSTR lpszProxy OPTIONAL, IN LPCSTR lpszProxyBypass OPTIONAL, IN DWORD dwFlags ) /*++ Routine Description: Opens a root Internet handle from which all HINTERNET objects are derived Arguments: lpszAgent - name of the application making the request (arbitrary identifying string). Used in "User-Agent" header when communicating with HTTP servers, if the application does not add a User-Agent header of its own dwAccessType - type of access required. Can be INTERNET_OPEN_TYPE_PRECONFIG - Gets the configuration from the registry INTERNET_OPEN_TYPE_DIRECT - Requests are made directly to the nominated server INTERNET_OPEN_TYPE_PROXY - Requests are made via the nominated proxy INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY - Like Pre-Config, but prevents JavaScript, INS and other auto-proxy types from being used. lpszProxy - if INTERNET_OPEN_TYPE_PROXY, a list of proxy servers to use lpszProxyBypass - if INTERNET_OPEN_TYPE_PROXY, a list of servers which we will communicate with directly dwFlags - flags to control the operation of this API or potentially all APIs called on the handle generated by this API. Currently supported are: INTERNET_FLAG_ASYNC - if specified then all subsequent API calls made against the handle returned from this API, or handles descended from the handle returned by this API, have the opportunity to complete asynchronously, depending on other factors relevant at the time the API is called Return Value: HINTERNET Success - handle of Internet object Failure - NULL. For more information, call GetLastError() --*/ { PERF_INIT(); DEBUG_ENTER_API((DBG_API, Handle, "InternetOpenA", "%q, %s (%d), %q, %q, %#x", lpszAgent, InternetMapOpenType(dwAccessType), dwAccessType, lpszProxy, lpszProxyBypass, dwFlags )); DWORD error; HINTERNET hInternet = NULL; if (!GlobalDataInitialized) { error = GlobalDataInitialize(); if (error != ERROR_SUCCESS) { goto quit; } } // // we are doing GetUserName here instead of in DLL_PROCESS_ATTACH // As every caller of wininet has to do this first, we ensure // that the username is initialized when they get to actually doing // any real operation // GetWininetUserName(); // // validate parameters // if (! ( (dwAccessType == INTERNET_OPEN_TYPE_DIRECT) || (dwAccessType == INTERNET_OPEN_TYPE_PROXY) || (dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG) || (dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY) || ( (dwAccessType == INTERNET_OPEN_TYPE_PROXY) && ( !ARGUMENT_PRESENT(lpszProxy) || (*lpszProxy == '\0') ) ) || (dwFlags & ~INTERNET_FLAGS_MASK) ) ) { error = ERROR_INVALID_PARAMETER; goto quit; } GlobalHaveInternetOpened = TRUE; // // Initalize an auto proxy dll if needed, // as long as the caller is allowing us free rein to do this // by calling us with INTERNET_OPEN_TYPE_PRECONFIG. // //if ( dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG ) //{ // if ( ! InitalizeAutoConfigDllIfNeeded() ) // { // error = GetLastError(); // // INET_ASSERT(error != ERROR_SUCCESS); // // goto quit; // } // // INTERNET_HANDLE_OBJECT * lpInternet; lpInternet = new INTERNET_HANDLE_OBJECT(lpszAgent, dwAccessType, (LPSTR)lpszProxy, (LPSTR)lpszProxyBypass, dwFlags ); if (lpInternet == NULL) { error = ERROR_NOT_ENOUGH_MEMORY; goto quit; } error = lpInternet->GetStatus(); if (error == ERROR_SUCCESS) { hInternet = (HINTERNET)lpInternet; // // success - don't return the object address, return the pseudo-handle // value we generated // hInternet = ((HANDLE_OBJECT *)hInternet)->GetPseudoHandle();//这里强制转发基类指针调用函数。(微软这个时候已经用的C++来写了) // // start async support now if required. If we can't start it, we'll get // another chance the next time we create an async request // if (dwFlags & INTERNET_FLAG_ASYNC) { InitializeAsyncSupport(); } } else { // // hack fix to stop InternetIndicateStatus (called from the handle // object destructor) blowing up if there is no handle object in the // thread info block. We can't call back anyway // LPINTERNET_THREAD_INFO lpThreadInfo = InternetGetThreadInfo(); if (lpThreadInfo) { // // BUGBUG - incorrect handle value // _InternetSetObjectHandle(lpThreadInfo, lpInternet, lpInternet); } // // we failed during initialization. Kill the handle using Dereference() // (in order to stop the debug version complaining about the reference // count not being 0. Invalidate for same reason) // lpInternet->Invalidate(); lpInternet->Dereference(); INET_ASSERT(hInternet == NULL); } quit: if (error != ERROR_SUCCESS) { DEBUG_ERROR(API, error); SetLastError(error); } DEBUG_LEAVE_API(hInternet); return hInternet; }
原文地址:http://blog.csdn.net/littlefishvc/article/details/40706937