在Visual Studio 6.0中使用WinHTTP

时间:2016-12-20 14:12:53

标签: c++ visual-studio visual-c++ vc6 winhttp

我正在维护用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

我添加了包含路径,如下图所示:

enter image description here

我已经添加了库的路径,如下图所示:

enter image description here

尝试编译后我得到了这个:

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(当然,如果可能的话)?

2 个答案:

答案 0 :(得分:3)

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

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

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

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

答案 1 :(得分:-1)

在VC 6.0中使用WinHTTP是完全可行的。您可以将它与SDK 5.0一起使用,即