【发布时间】: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.h 和 ConcurrencySal.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