
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
930
|
Chapter 16: Networking
Solution
Read the current Internet connectivity settings with the InternetSettingsReader class
provided for you in Example 16-13.
InternetSettingsReader calls some methods of
the
WinINet API via P/Invoke to retrieve current Internet connection information.
The majority of the work is done in setting up the structures that
WinINet uses and
then marshaling the structure pointers correctly to retrieve the values.
Example 16-13. InternetSettingsReader class
public class InternetSettingsReader
{
#region WinInet structures
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct InternetPerConnOptionList
{
public int dwSize; // size of the INTERNET_PER_CONN_OPTION_LIST struct
public IntPtr szConnection; // Connection name to set/query options
public int dwOptionCount; // Number of options to set/query
public int dwOptionError; // On error, which option failed
public IntPtr options;
};
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct InternetConnectionOption
{
static readonly int Size;
public PerConnOption m_Option;
public InternetConnectionOptionValue m_Value;
static InternetConnectionOption( )
{
InternetConnectionOption.Size =
Marshal.SizeOf(typeof(InternetConnectionOption));
}
// Nested Types
[StructLayout(LayoutKind.Explicit)] ...