Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Can't use WinHttpGetDefaultProxyConfiguration()



Permlink Replies: 5 - Last Post: Nov 20, 2014 2:28 PM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
Albert Wiersch

Posts: 35
Registered: 10/2/04
Can't use WinHttpGetDefaultProxyConfiguration()
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 19, 2014 6:47 AM
I'd like to use WinHttpGetDefaultProxyConfiguration() but can't get it
to work.

If I include winhttp.h, then I get compiler errors like this:

[bcc32 Error] Winhttp.h(111): E2238 Multiple declaration for
'HTTP_VERSION_INFO'
[bcc32 Error] Winhttp.h(111): E2238 Multiple declaration for
'LPHTTP_VERSION_INFO'

If I just copy the needed definitions/declarations from winhttp.h and
use only them by copying and pasting them into my own source file, then
I get a linker error:

[ilink32 Error] Error: Unresolved external '__stdcall
WinHttpGetDefaultProxyConfiguration(WINHTTP_PROXY_INFO *)' referenced
from ...

If I add:
#pragma link "winhttp.lib"

Then I still get the linker error.

I even tried creating a winhttp.lib file with implib and winhttp.dll and
added that to my project and that didn't work either.

How can I use WinHttpGetDefaultProxyConfiguration()? What am I missing?

--
Thanks,
Albert Wiersch
http://www.htmlvalidator.com/
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Can't use WinHttpGetDefaultProxyConfiguration()
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 19, 2014 8:55 AM   in response to: Albert Wiersch in response to: Albert Wiersch
Albert wrote:

If I include winhttp.h, then I get compiler errors like this:

[bcc32 Error] Winhttp.h(111): E2238 Multiple declaration for
'HTTP_VERSION_INFO'
[bcc32 Error] Winhttp.h(111): E2238 Multiple declaration for
'LPHTTP_VERSION_INFO'

You probably have wininet.h and winhttp.h included at the same time. They
define their own copies of some shared types.

If I just copy the needed definitions/declarations from winhttp.h and
use only them by copying and pasting them into my own source file,
then I get a linker error:

[ilink32 Error] Error: Unresolved external '__stdcall
WinHttpGetDefaultProxyConfiguration(WINHTTP_PROXY_INFO *)' referenced
from ...

If I add:
#pragma link "winhttp.lib"

Then I still get the linker error.

'#pragma link' is for .obj/.o files, you need to use '#pragma comment' for
.lib files:

#pragma comment(lib, "winhttp.lib")


--
Remy Lebeau (TeamB)
Albert Wiersch

Posts: 35
Registered: 10/2/04
Re: Can't use WinHttpGetDefaultProxyConfiguration()
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 19, 2014 3:06 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
On 11/19/2014 10:55 AM, Remy Lebeau (TeamB) wrote:

You probably have wininet.h and winhttp.h included at the same time. They
define their own copies of some shared types.

Hi Remy,

Thanks for the help!

So what is the best solution to this? What if I need both but can't use
it due to conflicts? Do I just manually copy what is needed from
winhttp.h and paste that into my source file and hope it's not the part
that conflicts?

#pragma comment(lib, "winhttp.lib")

Again, thanks! But I still can't get it to work.

I am creating the lib file like this:
C:\Windows\SysWOW64> implib C:\AlC_v150\lib\CSE_winhttp.lib .\winhttp.dll

Is winhttp.dll in C:\Windows\SysWOW64 the right one to use for a 32-bit
Win32 application?

I am including this in a cpp file:
#pragma comment(lib, "CSE_winhttp.lib")

I have the folder "C:\AlC_v150\lib" in my Library path.

But I still get:
[ilink32 Error] Error: Unresolved external '__stdcall
WinHttpGetDefaultProxyConfiguration(WINHTTP_PROXY_INFO *)' referenced
from ...

Any ideas as to what I'm doing wrong?

--
Thanks,
Albert Wiersch
http://www.htmlvalidator.com/
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Can't use WinHttpGetDefaultProxyConfiguration()
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 19, 2014 3:28 PM   in response to: Albert Wiersch in response to: Albert Wiersch
Albert wrote::

So what is the best solution to this?

Don't mix WinInet and WinHTTP together in the same source file. Use one
or the other. It is like saying don't mix WinSock1 and WinSock2 together
(winsock.h does not coexist with winsock2.h).

What if I need both but can't use it due to conflicts?

Put your WinInet code in one source file, and put your WinHTTP code in another
source file, and make sure they keep their respective headers separate from
each other. If they need to talk to each other, create an interface between
them.

I am creating the lib file like this:

You do not need to create .lib files manually. There are wininet.lib and
winhttp.lib files available in C++Builder's $(BDS)\lib\win32\release\psdk
folder.

Is winhttp.dll in C:\Windows\SysWOW64 the right one to use for
a 32-bit Win32 application?

Yes. And I can confirm that WinHttpGetDefaultProxyConfiguration() is exported
by it, at least in Windows 7.

--
Remy Lebeau (TeamB)
Albert Wiersch

Posts: 35
Registered: 10/2/04
Re: Can't use WinHttpGetDefaultProxyConfiguration()
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 20, 2014 8:14 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
On 11/19/2014 5:28 PM, Remy Lebeau (TeamB) wrote:
Albert wrote::

Yes. And I can confirm that WinHttpGetDefaultProxyConfiguration() is exported
by it, at least in Windows 7.

Hi Remy,

Thanks for the help but I couldn't get this to work as I wanted without
a lot of trouble, and when I did in a test project it still didn't seem
to return the proxy information I expected. Then I found out I can
simply read the proxy information I needed from a couple of values in
the registry, so I went with that.

But I did learn some things in the process. :)

--
Thanks,
Albert Wiersch
http://www.htmlvalidator.com/
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Can't use WinHttpGetDefaultProxyConfiguration()
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 20, 2014 2:28 PM   in response to: Albert Wiersch in response to: Albert Wiersch
Albert wrote:

Thanks for the help but I couldn't get this to work as I wanted
without a lot of trouble

Such as?

when I did in a test project it still didn't seem to return the proxy
information I expected.

What are you expecting exactly, and what is it returning instead?

Then I found out I can simply read the proxy information I needed
from a couple of values in the registry, so I went with that.

You really should not do that. Such functions exist for a reason. They
hide where and how the information is stored, and allows Microsoft to change
that in the future without breaking people's code.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02