- #include "stdafx.h"
- #include <Windows.h>
- #include <Winhttp.h>
- using namespace std;
- void main()
- {
- WINHTTP_CURRENT_USER_IE_PROXY_CONFIG MyProxyConfig;
- if(!WinHttpGetIEProxyConfigForCurrentUser(&MyProxyConfig))
- {
- //check the error
- DWORD Err = GetLastError();
- cout << "WinHttpGetIEProxyConfigForCurrentUser failed with the following error number: " << Err << endl;
- switch (Err)
- {
- case ERROR_FILE_NOT_FOUND:
- cout << "The error is ERROR_FILE_NOT_FOUND" << endl;
- break;
- case ERROR_WINHTTP_INTERNAL_ERROR:
- cout << "ERROR_WINHTTP_INTERNAL_ERROR" << endl;
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- cout << "ERROR_NOT_ENOUGH_MEMORY" << endl;
- break;
- default:
- cout << "Look up error in header file." << endl;
- }//end switch
- }//end if
- else
- {
- //no error so check the proxy settings and free any strings
- cout << "Auto Detect is: " << MyProxyConfig.fAutoDetect << endl;
- if(NULL != MyProxyConfig.lpszAutoConfigUrl)
- {
- wcout << "AutoConfigURL is: " << MyProxyConfig.lpszAutoConfigUrl << endl;
- GlobalFree(MyProxyConfig.lpszAutoConfigUrl);
- }
- if(NULL != MyProxyConfig.lpszProxy)
- {
- wcout << "AutoConfigURL is: " << MyProxyConfig.lpszProxy << endl;
- GlobalFree(MyProxyConfig.lpszProxy);
- }
- if(NULL != MyProxyConfig.lpszProxyBypass)
- {
- wcout << "AutoConfigURL is: " << MyProxyConfig.lpszProxyBypass << endl;
- GlobalFree(MyProxyConfig.lpszProxyBypass);
- }
- }//end else
- cout << "finished!";
- }//end main
- //该片段来自于http://www.codesnippet.cn/detail/031220137668.html
来源: http://www.codesnippet.cn/detail/031220137668.html