我正在维护用Visual Studio C++ 6.0编写的旧版应用程序。
我需要用对WinHTTP API的调用来替换部分代码。
我已经在Visual Studio 6.0测试项目中创建了一个小型演示,因此我可以看到情况如何。
构建代码时,出现以下错误(相同的代码在Visual Studio 2013中可以完美地工作):fatal error C1083: Cannot open include file: 'winhttp.h': No such file or directory我添加了包括路径,如下图所示:
c++ - 在Visual Studio 6.0中使用WinHTTP-LMLPHP
我已经添加了到库的路径,如下图所示:
c++ - 在Visual Studio 6.0中使用WinHTTP-LMLPHP
尝试编译后,我得到以下信息:

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
将新添加的路径移到顶部后,我只有一个错误: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我已经将sal.hConcurrencySal.h复制/粘贴到VC98 / Include中,并且还复制/粘贴了CodeAnalysis目录。
现在我得到以下错误:
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
目前,我正在Google搜索该问题的解决方案...
题:
您能否向我解释如何在Visual C++ 6中设置项目,以便它可以使用WinHTTP API(当然,如果可以的话)?

最佳答案

您不能将Windows v7.1 SDK与MSVC 6一起使用。此版本太新了,并且与该旧版本的编译器不兼容。

您将需要使用SDK的较早版本,该版本与MSVC 6兼容。最后一个兼容版本是2003年2月。如果您已订阅MSDN,则仍可以下载此文件。我不知道在哪里可以找到它;否则我见过的所有链接都消失了。

如果找不到此版本的SDK,或者它不包含对WinHTTP v5.1的支持,则可能需要回退到WinHTTP v5.0。这是一个单独的可再发行组件(winhttp5.dll),带有IE 5.01和更高版本的Windows NT 4支持该功能。使用MSVC 6来实现此目标应该没有问题。不幸的是,现在也不再支持此功能,并且不再提供下载(截至2004年10月)。您必须有一个旧副本。

动态调用所需的函数是最后的最后选择。您需要手动编写声明(或从最新的SDK header 移植声明),然后使用LoadModuleGetProcAddress动态调用导出的函数。这项工作很忙。也许首先研究升级您的编译器工具链。确保更新到新版本的MSVC不会很容易。很可能是这样;向后兼容比向前兼容容易得多。

09-13 00:02