How to check "Bypass proxy server for local addresses" connection option?
bool IsBypassLocalServer()
{
bool res = false;
INTERNET_PER_CONN_OPTION_LIST list;
memset(&list, 0, sizeof(list));
DWORD dwSize = sizeof(list);
INTERNET_PER_CONN_OPTION entry;
memset(&entry, 0, sizeof(entry));
entry.dwOption = INTERNET_PER_CONN_PROXY_BYPASS;
list.dwSize = sizeof(list);
list.dwOptionCount = 1;
list.pOptions = &entry;
if( InternetQueryOption(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, &dwSize) )
{
if( entry.Value.pszValue!=NULL )
{
res = StrStr(entry.Value.pszValue, _T("<local>"))!=NULL;
GlobalFree(entry.Value.pszValue);
entry.Value.pszValue = NULL;
}
}
return res;
}
Related articles:
Q226473 - HOWTO: Programmatically Query and Set Proxy Settings Under Internet Explorer
How to extract out the domain name of given URL?
There are few ways to do it. Microsoft Win32 Internet API
provides InternetCrackUrl. Look at example below:
#include <windows.h>
#include <wininet.h>
#include <tchar.h>
#pragma comment( lib, "wininet" )
BOOL GetHostName(LPCTSTR pszURL, LPTSTR pszHost, int cbHostBuf)
{
URL_COMPONENTS uc;
memset(&uc, 0, sizeof(uc));
uc.dwStructSize = sizeof(uc);
uc.lpszHostName = pszHost;
uc.dwHostNameLength = cbHostBuf;
return InternetCrackUrl(pszURL, lstrlen(pszURL), ICU_DECODE, &uc);
}
int main(int argc, char* argv[], char *envp[])
{
LPCTSTR pszURL = _T("http://www.microsoft.com/msdownload/platformsdk/setuplauncher.asp");
TCHAR szHost[1024];
szHost[0] = NULL;
if( GetHostName(pszURL, szHost, sizeof(szHost)/sizeof(TCHAR)) )
{
OutputDebugString(szHost);
}
return 0;
}
Shell provides nice Shell Lightweight Utility APIs. UrlGetPart function performs URL parsing. The following sample needs in latest Microsoft Platform
SDK - http://www.microsoft.com/msdownload/platformsdk/setuplauncher.asp
#include <windows.h>
#include <shlwapi.h>
#include <tchar.h>
#pragma comment( lib, "shlwapi" )
int main(int argc, char* argv[], char *envp[])
{
LPCTSTR pszURL = _T("http://www.microsoft.com/msdownload/platformsdk/setuplauncher.asp");
TCHAR szHost[1024];
szHost[0] = NULL;
DWORD cbHostBuf = sizeof(szHost)/sizeof(TCHAR);
// extract hostname
if( SUCCEEDED( UrlGetPart(pszURL, szHost, &cbHostBuf, URL_PART_HOSTNAME, NULL) ) )
{
OutputDebugString(szHost);
OutputDebugString(_T("\n"));
}
return 0;
}
Revision:2, Last Modified: May 27, 2003, by
Vadim Melnik.
Visit my
Homepage.