Use WinHTTP in Visual Studio 6.0

1.5k views Asked by At

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 the below image:

enter image description here

I have added the path to library, like in the below image:

enter image description here

After trying to compile I get this:

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'
    workaround.h(426) : 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:\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

At the moment I am Googling for a solution to this problem...

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) ?

2

There are 2 answers

5
Cody Gray - on strike On BEST ANSWER

You cannot use the Windows v7.1 SDK with MSVC 6. This version is too new and is not compatible with such an old version of the compiler.

You will need to use an older version of the SDK, one that is compatible with MSVC 6. The last compatible version is the February 2003 edition. You can still download this if you have an MSDN subscription. I have no idea where you can find it online otherwise; all of the links I've seen are dead.

If you cannot find this version of the SDK, or it doesn't include support for WinHTTP v5.1, you may need to fall back to WinHTTP v5.0. This was a separate redistributable (winhttp5.dll), and is supported by Windows NT 4 with IE 5.01 and later. You should have no problems targeting this using MSVC 6. Unfortunately, this is now unsupported, too, and is no longer available for download (as of October 2004). You'll have to have an old copy.

Calling the required functions dynamically is a final, last-resort option. You'll need to write the declarations manually (or port them from the latest SDK headers), and then use LoadModule and GetProcAddress to call the exported functions dynamically. This is a lot of busy work. Perhaps investigate upgrading your compiler toolchain first. Make sure it would not be easier to update to a newer version of MSVC. It very likely would be; backwards compatibility is much easier than forwards compatibility.

2
R00kie On

It is completely doable to use WinHTTP from within VC 6.0. You can use it with SDK 5.0 i.e.