【问题标题】:Use WinHTTP in Visual Studio 6.0在 Visual Studio 6.0 中使用 WinHTTP
【发布时间】:2017-05-05 18:55:27
【问题描述】:

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

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

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

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

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

目前我正在谷歌搜索这个问题的解决方案......

问题:

你能告诉我如何在 Visual C++ 6 中建立一个项目,以便它可以使用 WinHTTP API(当然,如果可能的话)?

【问题讨论】:

  • 拜托,你在winhttp.h之前包括了什么?
  • @Benoit: windows.h
  • 您可以在 Visual Studio 的 Any VC\include 子文件夹中找到 sal.h。这显然定义了__in__out-like 属性
  • @Benoit:我尝试在 VC98 包含文件夹中复制 sal.h,但出现更多错误。其他一些文件丢失了,但即使我添加了这些文件,新的错误也会不断弹出......
  • 在顶部包含 SDK,在 VC98 文件夹之前

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


【解决方案1】:

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

【讨论】:

  • 他问如何设置,而不仅仅是它是否可行。
  • 你知道哪里可以得到WinHTTP v5.0 SDK吗? Microsoft 于 2004 年 10 月停止提供下载。
【解决方案2】:

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

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

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

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

【讨论】:

  • 我担心可能是这种情况......为了正式接受你的回答,我必须先看看我的上级在这件事上的立场。我当然希望我们可以放弃 VS 6 并简单地使用最新的编译器,但如果这不是一个选项,那么我可能会被正式淘汰:(
  • 向后兼容比向前兼容容易得多。这是决定性的论点。我们决定慢慢迁移到更新的 Visual Studio。再次感谢。 + 1
  • @AlwaysLearningNewStuff 无论在何种情况下,我都会将受支持的工具链用于受支持的操作系统。鉴于 VS2013 仍然支持 XP(即使 XP 不支持 MS),如果不是 VS2015,我建议至少升级到那个。
  • @Mgetz:确实,我们将使用 VS 2013。谢谢您的建议。
  • 对不起。我不同意。我目前正在开发一个项目,该项目使用来自 SDK 7.1A 的 WinHttp 和 Visual C++ 6,没有任何问题。关键是将库引用添加到您的项目,并将包含和库目录添加到您的工作区。您还必须定义 DWORD_PTR 和 *PDWORD_PTR
猜你喜欢
  • 1970-01-01
  • 2021-08-23
  • 1970-01-01
  • 1970-01-01
  • 2020-10-26
  • 2016-07-13
  • 2012-05-23
  • 2015-01-21
  • 2015-04-22
相关资源
最近更新 更多