Thanks
Filip.
Try this
enum InternetOpenType
{
Preconfig = 0,
Direct = 1,
Proxy = 3,
PreconfigWithNoAutoProxy = 4
}
struct INTERNET_PROXY_INFO
{
public InternetOpenType dwAccessType;
public IntPtr lpszProxy,
lpszProxyBypass;
}
class InternetQueryOptionTest
{
// For INTERNET_OPTION_PROXY
[DllImport("wininet.dll", CharSet=CharSet.Auto, SetLastError=true)]
static extern bool InternetQueryOption(
IntPtr hInternet,
uint dwOption,
out INTERNET_PROXY_INFO lpBuffer,
ref int lpdwBufferLength);
const uint INTERNET_OPTION_PROXY = 38;
static void Main()
{
INTERNET_PROXY_INFO ipi;
int cb = Marshal.SizeOf(typeof(INTERNET_PROXY_INFO));
if ( InternetQueryOption( IntPtr.Zero, INTERNET_OPTION_PROXY,
out ipi, ref cb ) ) {
Console.WriteLine( ipi.dwAccessType );
if ( ipi.lpszProxy != IntPtr.Zero ) {
Console.WriteLine( Marshal.PtrToStringAuto( ipi.lpszProxy ) );
Marshal.FreeHGlobal( ipi.lpszProxy );
}
if ( ipi.lpszProxyBypass != IntPtr.Zero ) {
Console.WriteLine( Marshal.PtrToStringAuto(
ipi.lpszProxyBypass ) );
Marshal.FreeHGlobal( ipi.lpszProxyBypass );
}
}
else
throw new Win32Exception();
}
}
Mattias
===
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
"The data area passed to a system call is too small"
Error number from GetLastError is 122 (ERROR_INSUFFICIENT_BUFFER)
return 248 to cb value;
solutions?
Thanks
John
"Mattias Sjögren" <mattias.don...@mvps.org> wrote in message
news:eBrZMia#CHA....@TK2MSFTNGP11.phx.gbl...
First you get size of data (Calling InternetQueryOption for cb .value)
You must call InternetQueryOption twice with set cb.value (example 248);
Convert ProxyName to string you must use Marshal.PtrToStringAnsi(
ipi.lpszProxy) ;.....
VERY THANKS.!
John
"Mattias Sjögren" <mattias.don...@mvps.org> wrote in message
news:eBrZMia#CHA....@TK2MSFTNGP11.phx.gbl...
>
System.NullReferenceException occured in system.windows.forms.dll
"Object reference not set to an instance of an object"
"Mattias Sjögren" <mattias.don...@mvps.org> wrote in message
news:eBrZMia#CHA....@TK2MSFTNGP11.phx.gbl...
>
>Hi, thansk for example, i tested but.
>InternetQueryOption return False with this exception;
>
>"The data area passed to a system call is too small"
>Error number from GetLastError is 122 (ERROR_INSUFFICIENT_BUFFER)
Shoot, must be a docs bug then. OK, try it like this instead
struct INTERNET_PROXY_INFO
{
public InternetOpenType dwAccessType;
public string lpszProxy,
lpszProxyBypass;
}
class InternetQueryOptionTest
{
// For INTERNET_OPTION_PROXY
[DllImport("wininet.dll", CharSet=CharSet.Auto, SetLastError=true)]
static extern bool InternetQueryOption(
IntPtr hInternet,
uint dwOption,
IntPtr lpBuffer,
ref int lpdwBufferLength);
const uint INTERNET_OPTION_PROXY = 38;
static void Main()
{
int cb = 0;
InternetQueryOption( IntPtr.Zero, INTERNET_OPTION_PROXY,
IntPtr.Zero, ref cb );
IntPtr buffer = IntPtr.Zero;
try {
buffer = Marshal.AllocHGlobal( cb );
if ( InternetQueryOption( IntPtr.Zero, INTERNET_OPTION_PROXY,
buffer, ref cb ) ) {
INTERNET_PROXY_INFO ipi = (INTERNET_PROXY_INFO)
Marshal.PtrToStructure(buffer, typeof(INTERNET_PROXY_INFO));
Console.WriteLine( ipi.dwAccessType );
Console.WriteLine( ipi.lpszProxy );
Console.WriteLine( ipi.lpszProxyBypass );
}
else
throw new Win32Exception();
}
finally {
if ( buffer != IntPtr.Zero ) Marshal.FreeHGlobal( buffer );
}
}
}
>Next Problem....
>in Console Application works all fine.
>but if i transfer it to WinForms app, i get this exceptioin
>
>System.NullReferenceException occured in system.windows.forms.dll
>"Object reference not set to an instance of an object"
Does that happen with this code as well? If so, on which line?
"Mattias Sjögren" <mattias.don...@mvps.org> wrote in message
news:eA18Wvw#CHA....@TK2MSFTNGP12.phx.gbl...