WinInet API calls for Internet Options - How to do dis mon!?

  • Thread starter Java Writer via .NET 247
  • Start date
J

Java Writer via .NET 247

Hey Mon!,

This runs and gives me a 'iLen' of 4 but returns empty string. I am guessing this is the programmatic way to check Internet Explorer. {Tools}-{Internet Options)-(Settings...). Even if not I'd like to at least get something out of 'buffer'

The CODE:

class WinInet{
[DllImport("Wininet.dll")]
public static extern int InternetQueryOption (IntPtr hInternet, int dwOption, char[] buffer, ref int dwBufferLength );

public const int INTERNET_OPTION_BYPASS_EDITED_ENTRY =64;

public static string getInfo(){
char[] buffer = null;
int iLen = 0;
int iRet = InternetQueryOption (IntPtr.Zero,INTERNET_OPTION_BYPASS_EDITED_ENTRY , buffer, ref iLen);

buffer= new char[iLen];
int iRet2 = InternetQueryOption(IntPtr.Zero,INTERNET_OPTION_BYPASS_EDITED_ENTRY, buffer, ref iLen);

return new String(buffer);
}
}
 
W

Willy Denoyette [MVP]

Java Writer via .NET 247 said:
Hey Mon!,

This runs and gives me a 'iLen' of 4 but returns empty string. I am
guessing this is the programmatic way to check Internet Explorer.
{Tools}-{Internet Options)-(Settings...). Even if not I'd like to at
least get something out of 'buffer'

The CODE:

class WinInet{
[DllImport("Wininet.dll")]
public static extern int InternetQueryOption (IntPtr hInternet, int
dwOption, char[] buffer, ref int dwBufferLength );

public const int INTERNET_OPTION_BYPASS_EDITED_ENTRY =64;

public static string getInfo(){
char[] buffer = null;
int iLen = 0;
int iRet = InternetQueryOption
(IntPtr.Zero,INTERNET_OPTION_BYPASS_EDITED_ENTRY , buffer, ref iLen);

buffer= new char[iLen];
int iRet2 =
InternetQueryOption(IntPtr.Zero,INTERNET_OPTION_BYPASS_EDITED_ENTRY,
buffer, ref iLen);

return new String(buffer);
}
}

INTERNET_OPTION_BYPASS_EDITED_ENTRY returns a boolean in buffer (in C an
int value).
Following should do it...

[DllImport("Wininet.dll")]
public static extern int InternetQueryOption (IntPtr hInternet, int
dwOption, IntPtr buffer, ref int dwBufferLength );

public const int INTERNET_OPTION_BYPASS_EDITED_ENTRY =64;
static void Main()
{
Console.WriteLine(getInfo());

}

public static bool getInfo(){
IntPtr buffer = IntPtr.Zero;
int iLen = 0;
bool ret;
int iRet = InternetQueryOption
(IntPtr.Zero,INTERNET_OPTION_BYPASS_EDITED_ENTRY, buffer, ref iLen);
buffer = Marshal.AllocHGlobal(iLen);
// buffer points to an int ( a bool in C, 0 = false, != 0 true)
int iRet2 =
InternetQueryOption(IntPtr.Zero,INTERNET_OPTION_BYPASS_EDITED_ENTRY, buffer,
ref iLen);
ret = Convert.ToBoolean(Marshal.ReadInt32(buffer)); // convert int to
bool
Marshal.FreeHGlobal(buffer);
return ret;
}

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top