Discussion:
wininet autoproxy example broken?
(too old to reply)
Wayne Scott
2004-07-28 19:01:02 UTC
Permalink
I am trying to using the InternetGetProxyInfo API described on this page.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/autoproxy_support_in_wininet.asp

If I compile that compile autoproxy example program at the above URL, it always segfaults inside to call to InternetGetProxyInfo. Does any have a working example of how to use that code? Can anyone make the example work?

I want to find the proxy that IE would use for a given URL when talk to automatically detect proxy settings.

Thanks,
-Wayne
***@bitmover.com
Stephen Sulzer
2004-07-28 20:48:33 UTC
Permalink
Hi Wayne,

Don't know if this will help, but did you copy the sample code exactly as
is? Note that the strings used to initialize the url and host variables have
a syntax problem. The URLs should not be enclosed in angle brackets (< >),
and I don't think the host variable should be a full URL. Those variables
should be declared as:

char url[1025] = "http://www.microsoft.com/windows/default.mspx";
char host[256] = "www.microsoft.com";


Stephen
Post by Wayne Scott
I am trying to using the InternetGetProxyInfo API described on this page.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/autoproxy_support_in_wininet.asp
Post by Wayne Scott
If I compile that compile autoproxy example program at the above URL, it
always segfaults inside to call to InternetGetProxyInfo. Does any have a
working example of how to use that code? Can anyone make the example work?
Post by Wayne Scott
I want to find the proxy that IE would use for a given URL when talk to
automatically detect proxy settings.
Post by Wayne Scott
Thanks,
-Wayne
Stephen Sulzer
2004-07-29 01:05:50 UTC
Permalink
InternetGetProxyInfo returns a string pointer (via the LPSTR*
lplpszProxyHostName output parameter) that it allocates using GlobalAlloc;
the caller is not required to pass in a pre-allocated buffer. The sample
code sets the proxy variable to a pre-allocated proxyBuffer variable, which
is unnecessary. The 'char * proxy' variable type is correct, and the caller
is expected to free the proxy string using GlobalFree().

Some things to check:

- When you run the sample code, do DetectAutoProxyUrl() and
URLDownloadToFile() successfully download the WPAD script file? What does
the WPAD script code look like? (if you can share it)

- Does the call to InternetInitializeAutoProxyDll() return 1 (success)?

- In the call to InternetGetProxyInfo() make sure the correct string lengths
of the url and host variables are given. If you changed the declaration of
the url and host variables from char arrays to char *, then you cannot use
sizeof( ) to compute the string length.

Stephen
Post by Stephen Sulzer
Don't know if this will help, but did you copy the sample code exactly as
is? Note that the strings used to initialize the url and host variables have
a syntax problem. The URLs should not be enclosed in angle brackets (<
),
Post by Stephen Sulzer
and I don't think the host variable should be a full URL. Those variables
char url[1025] = "http://www.microsoft.com/windows/default.mspx";
char host[256] = "www.microsoft.com";
Stephen
Thanks. I saw the same problem and tried the same fix. It doesn't change
the result. We still try to dereference a null pointer is jscript.dll.
Also I find the interface to InternetGetProxyInfo strange. The example
code
is written as if you pass a buffer where the result should be written.
(The 'proxy' var in the code) But if that was the case why is that
parameter
a 'char **' instead of just a 'char *'. The API suggest it might malloc
the
return value and then return the pointer. I have tried it both ways with
no luck.
-Wayne
Loading...