
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Use the Current Internet Connection Settings
|
935
Using the InternetSettingsReader is demonstrated in the GetInternetSettings
method shown in Example 16-16. The proxy information is retrieved and displayed
to the console here, but could easily be stored in another program for use as proxy
information when connecting. See Recipe 14.7 for details on setting up the proxy
information for a
WebRequest.
// Initialize the option for the data we want.
ico.m_Option = pco;
//Initialize the option list for the default connection or LAN
int listSize = Marshal.SizeOf(perConnOptList);
perConnOptList.dwSize = listSize;
perConnOptList.szConnection = IntPtr.Zero;
perConnOptList.dwOptionCount = 1;
perConnOptList.dwOptionError = 0;
// Figure out sizes and offsets.
int icoSize = Marshal.SizeOf(ico);
int optionTotalSize = icoSize;
// Alloc enough memory for the option.
perConnOptList.options =
Marshal.AllocCoTaskMem(icoSize);
long icoOffset = (long)perConnOptList.options + (long)icoSize;
// Make pointer from the structure.
IntPtr optionListPtr = perConnOptList.options;
Marshal.StructureToPtr(ico, optionListPtr, false);
// Make the query.
if (InternetQueryOption(
IntPtr.Zero,
75, //(int)InternetOption.INTERNET_OPTION_PER_CONNECTION_OPTION,
ref perConnOptList,
ref listSize) == true)
{
// Retrieve ...