I'm trying to make an application compatible with the auto proxy API provided by the WinINet library in order to make local pac files work, and am stuck with the error ERROR_CAN_NOT_COMPLETE when trying to call InternetGetProxyInfo...
I have been following the post of Eric Loewenthal (dev @Microsoft so I hope his suggestion are A-OK ;p) in here and the idea should be:
- Call the InternetInitializeAutoProxyDll function;
- Call the InternetGetProxyInfo to get the proxy URL for each given requested URLs;
- Call the InternetDeInitializeAutoProxyDll at the end.
Here is how my code looks like :
// Start by initializing the Auto proxy stuff
BOOL ok = InternetInitializeAutoProxyDll(0, pathToTheProxyPACFile,
NULL, NULL, NULL);
// Here ok is true so I consider the initialization was a success
// [...]
// Later on, I try to get the proxy used for each requested URL like this:
LPSTR proxyURL = NULL;
DWORD proxyURLLength = 0;
BOOL ok = InternetGetProxyInfo(requestedURL,
requestedURLLength,
hostName,
hostNameLength,
&proxyURL,
&proxyURLLength);
// Here ok is false, the proxy url and length are left as is,
// and a call to GetLastError() returns 1003 :s
I can't see what's wrong with that, and couldn't find any convincing example on the net (and the documentation is severely lacking...).
Please note I tried allocating a buffer for proxyURL and setting its size to proxyURLLength as the documentation isn't clear about how the memory should be handled, but it doesn't work and my understanding is that I should let WinINet handle it anyway, and use GlobalFree on proxyURL in case of success.
I have also tried using InternetCrackUrlA in order to get the host name just in case the class I use to get the host name from the requested URL was not ok with this API (and indeed, InternetCrackUrlA considers the port to be part of the host name...), but it didn't help either.
Please let me know of any suggestion that might help me get this to work ;)
PS: I have been using WinHTTP to do the same thing in the same part of the code and it works correctly. PPS: I am testing this on windows XP with IE8 installed.
Edit ==========> I have coded another program that only calls these functions, and in this case I don't experience any problem, so I guess my problem comes not from the way I call InternetGetProxyInfo but from the state I'm in when I call it, that is within an implementation of the event sink used for our embedded IE, unless there is a problem with my includes or something along those lines..?