Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am maintaining a legacy app written in Visual Studio C++ 6.0.

I need to replace portion of the code with calls to WinHTTP API.

I have created small demo in Visual Studio 6.0 test project so I can see how would things go.

When I build the code I get the following error ( the same code works flawlessly in Visual Studio 2013 ) :

fatal error C1083: Cannot open include file: 'winhttp.h': No such file or directory

I have added the Include path, like in this[^] image.

I have added the path to library, like in this[^] image.

After trying to compile I get this:
C++
error C2146: syntax error : missing ';' before identifier 'dwResult'
error C2501: 'DWORD_PTR' : missing storage-class or type specifiers
error C2501: 'dwResult' : missing storage-class or type specifiers
error C2065: '__in' : undeclared identifier
error C2143: syntax error : missing ')' before 'const'
warning C4229: anachronism used : modifiers on data are ignored
error C2491: 'WinHttpTimeFromSystemTime' : definition of dllimport data not allowed
error C2059: syntax error : ')'
error C2065: '__in_z' : undeclared identifier
error C2146: syntax error : missing ')' before identifier 'LPCWSTR'
warning C4229: anachronism used : modifiers on data are ignored
error C2491: 'WinHttpTimeToSystemTime' : definition of dllimport data not allowed
error C2059: syntax error : ')'
error C2065: '__in_ecount' : undeclared identifier
error C2065: 'dwUrlLength' : undeclared identifier
error C2146: syntax error : missing ')' before identifier 'LPCWSTR'
warning C4229: anachronism used : modifiers on data are ignored
error C2491: 'WinHttpCrackUrl' : definition of dllimport data not allowed
error C2059: syntax error : ')'
error C2146: syntax error : missing ')' before identifier 'LPURL_COMPONENTS'
warning C4229: anachronism used : modifiers on data are ignored
error C2491: 'WinHttpCreateUrl' : definition of dllimport data not allowed
error C2059: syntax error : ')'
error C2065: '__in_z_opt' : undeclared identifier
error C2146: syntax error : missing ')' before identifier 'LPCWSTR'
warning C4229: anachronism used : modifiers on data are ignored
error C2491: 'WinHttpOpen' : definition of dllimport data not allowed
error C2440: 'initializing' : cannot convert from 'int' to 'void *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
error C2059: syntax error : ')'
error C2061: syntax error : identifier '__out_bcount_part'
error C2061: syntax error : identifier '__in_bcount_opt'
error C2061: syntax error : identifier '__out_data_source'
error C2059: syntax error : 'return'
warning C4518: '__declspec(dllimport ) ' : storage-class or type specifier(s) unexpected here; ignored
error C2146: syntax error : missing ';' before identifier 'BOOL'
fatal error C1004: unexpected end of file found

After moving the newly added paths to the top, I have got only one error:

c:\program files (x86)\microsoft sdks\windows\v7.1a\include\specstrings.h(11) : fatal error C1083: Cannot open include file: 'sal.h': No such file or directory

I have copy/pasted sal.h and ConcurrencySal.h into VC98/Include, and have copy/pasted directory CodeAnalysis as well.

Now I get following errors:
C++
c:\program files (x86)\microsoft visual studio\vc98\include\sal.h(708) : warning C4068: unknown pragma
c:\program files (x86)\microsoft visual studio\vc98\include\sal.h(1472) : warning C4068: unknown pragma
c:\program files (x86)\microsoft visual studio\vc98\include\sal.h(2866) : warning C4005: '__useHeader' : macro redefinition
        c:\program files (x86)\microsoft sdks\windows\v7.1a\include\sal_supp.h(57) : see previous definition of '__useHeader'
c:\program files (x86)\microsoft visual studio\vc98\include\sal.h(2876) : warning C4005: '__on_failure' : macro redefinition
        c:\program files (x86)\microsoft sdks\windows\v7.1a\include\specstrings_supp.h(77) : see previous definition of '__on_failure'
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\winnt.h(3994) : warning C4035: 'ReadPMC' : no return value
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\winnt.h(4023) : warning C4035: 'ReadTimeStampCounter' : no return value
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\winnt.h(12804) : error C2144: syntax error : missing ';' before type 'int'
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\winnt.h(12804) : error C2501: '__inner_checkReturn' : missing storage-class or type specifiers
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\winnt.h(12804) : fatal error C1004: unexpected end of file found

QUESTION:

Can you explain to me how to set up a project in Visual C++ 6 so it can use WinHTTP API (of course, if it is possible at all) ?

What I have tried:

At the moment I am Googling for a solution to this problem...
Posted
Updated 20-Dec-16 5:56am
v2

You are trying to use the Windows SDK version 7.1A with Visual Studio 6. This won't work.

The last SDK that supports Visual Studio 6 is the Microsoft Platform SDK February 2003 (version 5.2.3790.0) (source: Microsoft Windows SDK - Wikipedia[^]). Note that you have to install the full SDK to have the WinHttp header and library file included.

So you have three options:

  1. Port the application to be build with a newer Visual Studio version
  2. Use the WinINet API instead of the WinHTTP API
  3. Install the full PSDK Feb. 2003 or older for use with Visual Studio 6
 
Share this answer
 
Comments
MyOldAccount 21-Dec-16 6:14am    
Thank you, 5ed.

For future readers: We have decided to slowly migrate to the newer version of Visual Studio. We did not want to force matters by hunting for PSDK from February 2003.
Jochen Arndt 21-Dec-16 6:45am    
Thank you for your feedback.

It is a good decision to get rid of a 19 year old development suite. Hopefully porting the project is not too complex.
Because winhttp is a high level API you MUST include the standard windows header at first . That will solve the most problems in your code.
the correct way is with braces:
C++
#include <windows.h> 
#include <winhttp.h> 

Set the sdk search path at the last position to avoid collisions. And you must include the winhttp.lib file on the linker tabs.

Take also a look at the winhttp examples from Microsoft.

You better use some never version of Visual Studio, I prefer the VS 2005 or VS 2010.
 
Share this answer
 
Comments
MyOldAccount 20-Dec-16 11:52am    
Because winhttp is a high level API you MUST include the standard windows header at first .

I have done that at the very start, that is not the cause of the problem. :(

Set the sdk search path at the last position to avoid collisions.

Did that, but still got problems...

And you must include the winhttp.lib file on the linker tabs.

Did that too (with #pragma comment) still same result

You better use some never version of Visual Studio

At the moment, I can only use VS 6.

Thank you for trying to help, I have updated OP with new info...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900