3

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

Community
  • 1
  • 1
AlwaysLearningNewStuff
  • 2,939
  • 3
  • 31
  • 84
  • Please, what are you including before winhttp.h? – Benoit Dec 20 '16 at 14:28
  • @Benoit: `windows.h` – AlwaysLearningNewStuff Dec 20 '16 at 14:29
  • You can find `sal.h` in Any `VC\include` subfolder of Visual Studio. This apparently defines `__in` or `__out`-like attributes – Benoit Dec 20 '16 at 14:41
  • @Benoit: I have tried to copy `sal.h` in VC98 include folder but got more errors. Some other files were missing, but even when I add those, new errors keep popping out... – AlwaysLearningNewStuff Dec 20 '16 at 14:46
  • include SDK at top, before VC98 folders – RbMm Dec 20 '16 at 16:10
  • @RbMm: If you think on `c:\program files (x86)\microsoft sdks\windows\v7.1a\include` I have already done that (same goes for libraries). Now it can not find `sal.h`. After copying that header into VC98 Include, I got more errors -> some files were missing. After adding those I still got errors. At the moment I am Googling in desperate hope some other approach might be the solution. Thanks for trying to help. – AlwaysLearningNewStuff Dec 20 '16 at 16:17

2 Answers2

3

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.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • I was afraid that might be the case... In order to officially accept your answer I must first see the standings of my superiors on this matter. I sure hope we can ditch VS 6 and simply use newest compilers, but if this is not an option than I might be officially busted :( – AlwaysLearningNewStuff Dec 20 '16 at 16:07
  • *backwards compatibility is much easier than forwards compatibility.* That was the decisive argument. We have decided to slowly move to newer Visual Studio. Thanks again. + 1 – AlwaysLearningNewStuff Dec 21 '16 at 11:15
  • @AlwaysLearningNewStuff whatever the case I'd be using the supported toolchain for a supported operating system. And given that VS2013 still supports XP (even though XP is out of support from MS) I would suggest at least upgrading to that if not VS2015. – Mgetz Dec 21 '16 at 11:24
  • @Mgetz: Indeed, we will use VS 2013. Thank you for the suggestion. – AlwaysLearningNewStuff Dec 21 '16 at 11:30
  • Sorry. I do not agree. I am currently working on a project that uses WinHttp from SDK 7.1A with Visual C++ 6 without any problems. The key is to add library reference to your project and include and library directories to your workspace. You also have to define DWORD_PTR and *PDWORD_PTR – Vladimir Kocjancic Mar 29 '17 at 10:18
-1

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

R00kie
  • 1
  • 1