我试着找出gcc/g++编译器抛出错误的原因:
.\http.cpp: In function 'int main()':
.\http.cpp:14:5: error: 'WinHttpOpen' was not declared in this scope
WinHttpOpen( L"A WinHTTP Example Program/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
下面我把我的代码。这很奇怪,因为我是根据MSDN文档编写的。
#include <stdio.h>
#include <winhttp.h>
#pragma comment(lib, "winhttp.lib");
using namespace std;
int main(void){
bool bResults = false;
// HINTERNET hSession = NULL;
// HINTERNET hConnect = NULL;
// HINTERNET hRequest = NULL;
// Use WinHttpOpen to obtain a session handle.
WinHttpOpen( L"A WinHTTP Example Program/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
// Specify an HTTP server.
// if (hSession)
// hConnect = WinHttpConnect( hSession, L"www.wp.pl",
// INTERNET_DEFAULT_HTTP_PORT, 0);
// // Create an HTTP Request handle.
// if (hConnect)
// hRequest = WinHttpOpenRequest( hConnect, L"GET",
// L"/writetst.txt",
// NULL, WINHTTP_NO_REFERER,
// WINHTTP_DEFAULT_ACCEPT_TYPES,
// 0);
// Send a Request.
// if (hRequest)
// bResults = WinHttpSendRequest( hRequest,
// WINHTTP_NO_ADDITIONAL_HEADERS,
// 0, WINHTTP_NO_REQUEST_DATA, 0,
// 0, 0);
// Place additional code here.
// Report errors.
// if (!bResults)
// printf("Error %d has occurred.\n",GetLastError());
// // Close open handles.
// if (hRequest) WinHttpCloseHandle(hRequest);
// if (hConnect) WinHttpCloseHandle(hConnect);
// if (hSession) WinHttpCloseHandle(hSession);
return 0;
}
您有什么建议吗?我注释掉了部分代码,但这并不重要,错误总是一样的。
编辑:
操作系统: Windows 10 x64,
IDE:代码,
编译器: gcc版本8.1.0 (x86_64-win32-seh-rev0,由MinGW-W64项目构建)
我按照建议@Han和我的代码如下所示:
#include <stdio.h>
#include <winhttp.h>
#include <windows.h>
#include <wininet.h>
int main(void){
HINTERNET hSession = NULL; // here is problem
HINTERNET hConnect = NULL; // here is problem
HINTERNET hRequest = NULL; // here is problem
bool bResults = false;
// Use WinHttpOpen to obtain a session handle.
WinHttpOpen( L"A WinHTTP Example Program/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
return 0;
}
注意:如果删除HINSTANCE变量,编译器将正确工作,但如果添加这些变量,编译器将抛出一个异常,如下所示:
PS > g++.exe .\http.cpp -o http.exe -lwinhttp
In file included from .\http.cpp:2:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:32:9: error: 'LPVOID' does not name a type; did you mean 'VOID'?
typedef LPVOID HINTERNET;
^~~~~~
VOID
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:33:9: error: 'HINTERNET' does not name a type; did you mean 'INTERNETAPI'?
typedef HINTERNET *LPHINTERNET;
^~~~~~~~~
INTERNETAPI
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:38:9: error: 'WORD' does not name a type; did you mean 'HIWORD'?
typedef WORD INTERNET_PORT;
^~~~
HIWORD
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:39:9: error: 'INTERNET_PORT' does not name a type; did you mean 'INTERNETAPI_'?
typedef INTERNET_PORT *LPINTERNET_PORT;
^~~~~~~~~~~~~
INTERNETAPI_
In file included from .\http.cpp:2:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:465:5: error: 'DWORD' does not name a type; did you mean 'HIWORD'?
DWORD dwStructSize;
^~~~~
HIWORD
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:466:5: error: 'LPWSTR' does not name a type; did you mean 'LPTR'?
LPWSTR lpszScheme;
^~~~~~
LPTR
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:467:5: error: 'DWORD' does not name a type; did you mean 'HIWORD'?
DWORD dwSchemeLength;
^~~~~
HIWORD
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:469:5: error: 'LPWSTR' does not name a type; did you mean 'LPTR'?
LPWSTR lpszHostName;
^~~~~~
LPTR
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:470:5: error: 'DWORD' does not name a type; did you mean 'HIWORD'?
DWORD dwHostNameLength;
^~~~~
HIWORD
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:471:5: error: 'INTERNET_PORT' does not name a type; did you mean 'INTERNETAPI_'?
INTERNET_PORT nPort;
^~~~~~~~~~~~~
INTERNETAPI_
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:472:5: error: 'LPWSTR' does not name a type; did you mean 'LPTR'?
LPWSTR lpszUserName;
^~~~~~
LPTR
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:473:5: error: 'DWORD' does not name a type; did you mean 'HIWORD'?
DWORD dwUserNameLength;
^~~~~
HIWORD
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:474:5: error: 'LPWSTR' does not name a type; did you mean 'LPTR'?
LPWSTR lpszPassword;
^~~~~~
LPTR
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:475:5: error: 'DWORD' does not name a type; did you mean 'HIWORD'?
DWORD dwPasswordLength;
^~~~~
HIWORD
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:476:5: error: 'LPWSTR' does not name a type; did you mean 'LPTR'?
LPWSTR lpszUrlPath;
^~~~~~
LPTR
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:477:5: error: 'DWORD' does not name a type; did you mean 'HIWORD'?
DWORD dwUrlPathLength;
^~~~~
HIWORD
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:478:5: error: 'LPWSTR' does not name a type; did you mean 'LPTR'?
LPWSTR lpszExtraInfo;
^~~~~~
LPTR
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:479:5: error: 'DWORD' does not name a type; did you mean 'HIWORD'?
DWORD dwExtraInfoLength;
^~~~~
HIWORD
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:486:5: error: 'DWORD_PTR' does not name a type
DWORD_PTR dwResult;
^~~~~~~~~
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:487:5: error: 'DWORD' does not name a type; did you mean 'HIWORD'?
DWORD dwError;
^~~~~
HIWORD
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:492:5: error: 'FILETIME' does not name a type; did you mean 'ETIME'?
FILETIME ftExpiry;
^~~~~~~~
ETIME
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:493:5: error: 'FILETIME' does not name a type; did you mean 'ETIME'?
FILETIME ftStart;
^~~~~~~~
ETIME
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:494:5: error: 'LPWSTR' does not name a type; did you mean 'LPTR'?
LPWSTR lpszSubjectInfo;
^~~~~~
LPTR
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:495:5: error: 'LPWSTR' does not name a type; did you mean 'LPTR'?
LPWSTR lpszIssuerInfo;
^~~~~~
LPTR
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:496:5: error: 'LPWSTR' does not name a type; did you mean 'LPTR'?
LPWSTR lpszProtocolName;
^~~~~~
LPTR
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:497:5: error: 'LPWSTR' does not name a type; did you mean 'LPTR'?
LPWSTR lpszSignatureAlgName;
^~~~~~
LPTR
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:498:5: error: 'LPWSTR' does not name a type; did you mean 'LPTR'?
LPWSTR lpszEncryptionAlgName;
^~~~~~
LPTR
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:499:5: error: 'DWORD' does not name a type; did you mean 'HIWORD'?
DWORD dwKeySize;
^~~~~
HIWORD
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:504:5: error: 'DWORD' does not name a type; did you mean 'HIWORD'?
DWORD dwAccessType;
^~~~~
HIWORD
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:505:5: error: 'LPWSTR' does not name a type; did you mean 'LPTR'?
LPWSTR lpszProxy;
^~~~~~
LPTR
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:506:5: error: 'LPWSTR' does not name a type; did you mean 'LPTR'?
LPWSTR lpszProxyBypass;
^~~~~~
LPTR
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:513:5: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL fAutoDetect;
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:514:5: error: 'LPWSTR' does not name a type; did you mean 'LPTR'?
LPWSTR lpszAutoConfigUrl;
^~~~~~
LPTR
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:515:5: error: 'LPWSTR' does not name a type; did you mean 'LPTR'?
LPWSTR lpszProxy;
^~~~~~
LPTR
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:516:5: error: 'LPWSTR' does not name a type; did you mean 'LPTR'?
LPWSTR lpszProxyBypass;
^~~~~~
LPTR
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:519:15: error: typedef 'VOID' is initialized (use decltype instead)
typedef VOID (CALLBACK *WINHTTP_STATUS_CALLBACK)(HINTERNET,DWORD_PTR,DWORD,LPVOID,DWORD);
^~~~~~~~
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:519:15: error: 'CALLBACK' was not declared in this scope
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:519:15: note: the macro 'CALLBACK' had not yet been defined
In file included from C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/windef.h:8,
from C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/windows.h:69,
from .\http.cpp:3:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/minwindef.h:90: note: it was later defined here
#define CALLBACK __stdcall
In file included from .\http.cpp:2:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:519:25: error: 'WINHTTP_STATUS_CALLBACK' was not declared in this scope
typedef VOID (CALLBACK *WINHTTP_STATUS_CALLBACK)(HINTERNET,DWORD_PTR,DWORD,LPVOID,DWORD);
^~~~~~~~~~~~~~~~~~~~~~~
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:519:25: note: suggested alternative: 'WINHTTP_OPTION_CALLBACK'
typedef VOID (CALLBACK *WINHTTP_STATUS_CALLBACK)(HINTERNET,DWORD_PTR,DWORD,LPVOID,DWORD);
^~~~~~~~~~~~~~~~~~~~~~~
WINHTTP_OPTION_CALLBACK
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:531:5: error: 'DWORD' does not name a type; did you mean 'HIWORD'?
DWORD dwFlags;
^~~~~
HIWORD
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:532:5: error: 'DWORD' does not name a type; did you mean 'HIWORD'?
DWORD dwAutoDetectFlags;
^~~~~
HIWORD
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:533:5: error: 'LPCWSTR' does not name a type; did you mean 'LPTR'?
LPCWSTR lpszAutoConfigUrl;
^~~~~~~
LPTR
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:534:5: error: 'LPVOID' does not name a type; did you mean 'VOID'?
LPVOID lpvReserved;
^~~~~~
VOID
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:535:5: error: 'DWORD' does not name a type; did you mean 'HIWORD'?
DWORD dwReserved;
^~~~~
HIWORD
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:536:5: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL fAutoLogonIfChallenged;
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:541:5: error: 'DWORD' does not name a type; did you mean 'HIWORD'?
DWORD dwMajorVersion;
^~~~~
HIWORD
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:542:5: error: 'DWORD' does not name a type; did you mean 'HIWORD'?
DWORD dwMinorVersion;
^~~~~
HIWORD
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:558:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpAddRequestHeaders(HINTERNET,LPCWSTR,DWORD,DWORD);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:559:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpDetectAutoProxyConfigUrl(DWORD,LPWSTR*);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:560:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpCheckPlatform(void);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:561:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpCloseHandle(HINTERNET);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:562:1: error: 'HINTERNET' does not name a type; did you mean 'INTERNETAPI'?
HINTERNET WINAPI WinHttpConnect(HINTERNET,LPCWSTR,INTERNET_PORT,DWORD);
^~~~~~~~~
INTERNETAPI
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:563:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpCrackUrl(LPCWSTR,DWORD,DWORD,LPURL_COMPONENTS);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:564:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpCreateUrl(LPURL_COMPONENTS,DWORD,LPWSTR,LPDWORD);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:565:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpGetDefaultProxyConfiguration(WINHTTP_PROXY_INFO*);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:566:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpGetIEProxyConfigForCurrentUser(WINHTTP_CURRENT_USER_IE_PROXY_CONFIG*);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:567:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpGetProxyForUrl(HINTERNET,LPCWSTR,WINHTTP_AUTOPROXY_OPTIONS*,WINHTTP_PROXY_INFO*);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:568:1: error: 'HINTERNET' does not name a type; did you mean 'INTERNETAPI'?
HINTERNET WINAPI WinHttpOpen(LPCWSTR,DWORD,LPCWSTR,LPCWSTR,DWORD);
^~~~~~~~~
INTERNETAPI
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:569:1: error: 'HINTERNET' does not name a type; did you mean 'INTERNETAPI'?
HINTERNET WINAPI WinHttpOpenRequest(HINTERNET,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR*,DWORD);
^~~~~~~~~
INTERNETAPI
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:570:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpQueryAuthParams(HINTERNET,DWORD,LPVOID*);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:571:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpQueryAuthSchemes(HINTERNET,LPDWORD,LPDWORD,LPDWORD);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:572:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpQueryDataAvailable(HINTERNET,LPDWORD);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:573:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpQueryHeaders(HINTERNET,DWORD,LPCWSTR,LPVOID,LPDWORD,LPDWORD);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:574:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpQueryOption(HINTERNET,DWORD,LPVOID,LPDWORD);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:575:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpReadData(HINTERNET,LPVOID,DWORD,LPDWORD);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:576:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpReceiveResponse(HINTERNET,LPVOID);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:577:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpSendRequest(HINTERNET,LPCWSTR,DWORD,LPVOID,DWORD,DWORD,DWORD_PTR);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:578:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpSetDefaultProxyConfiguration(WINHTTP_PROXY_INFO*);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:579:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpSetCredentials(HINTERNET,DWORD,DWORD,LPCWSTR,LPCWSTR,LPVOID);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:580:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpSetOption(HINTERNET,DWORD,LPVOID,DWORD);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:581:1: error: 'WINHTTP_STATUS_CALLBACK' does not name a type; did you mean 'WINHTTP_OPTION_CALLBACK'?
WINHTTP_STATUS_CALLBACK WINAPI WinHttpSetStatusCallback(HINTERNET,WINHTTP_STATUS_CALLBACK,DWORD,DWORD_PTR);
^~~~~~~~~~~~~~~~~~~~~~~
WINHTTP_OPTION_CALLBACK
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:582:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpSetTimeouts(HINTERNET,int,int,int,int);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:583:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpTimeFromSystemTime(const SYSTEMTIME *,LPWSTR);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:584:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpTimeToSystemTime(LPCWSTR,SYSTEMTIME*);
^~~~~~~
V_BOOL
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:585:1: error: 'WINBOOL' does not name a type; did you mean 'V_BOOL'?
WINBOOL WINAPI WinHttpWriteData(HINTERNET,LPCVOID,DWORD,LPDWORD);
^~~~~~~
V_BOOL
In file included from .\http.cpp:2:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/wininet.h:123:91: error: expected identifier before numeric constant
INTERNET_SCHEME_PARTIAL = -2,INTERNET_SCHEME_UNKNOWN = -1,INTERNET_SCHEME_DEFAULT = 0,INTERNET_SCHEME_FTP,INTERNET_SCHEME_GOPHER,
^~~~~~~~~~~~~~~~~~~
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/wininet.h:123:91: error: expected '}' before numeric constant
In file included from .\http.cpp:4:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/wininet.h:122:16: note: to match this '{'
typedef enum {
^
In file included from .\http.cpp:2:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/wininet.h:123:91: error: expected unqualified-id before numeric constant
INTERNET_SCHEME_PARTIAL = -2,INTERNET_SCHEME_UNKNOWN = -1,INTERNET_SCHEME_DEFAULT = 0,INTERNET_SCHEME_FTP,INTERNET_SCHEME_GOPHER,
^~~~~~~~~~~~~~~~~~~
In file included from .\http.cpp:4:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/wininet.h:127:20: error: expected unqualified-id before ',' token
} INTERNET_SCHEME,*LPINTERNET_SCHEME;
^
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/wininet.h:127:22: error: 'INTERNET_SCHEME* LPINTERNET_SCHEME' redeclared as different kind of symbol
} INTERNET_SCHEME,*LPINTERNET_SCHEME;
^~~~~~~~~~~~~~~~~
In file included from .\http.cpp:2:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:46:31: note: previous declaration 'typedef int* LPINTERNET_SCHEME'
typedef int INTERNET_SCHEME, *LPINTERNET_SCHEME;
^~~~~~~~~~~~~~~~~
In file included from .\http.cpp:4:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/wininet.h:224:5: error: conflicting declaration 'typedef struct HTTP_VERSION_INFO HTTP_VERSION_INFO'
} HTTP_VERSION_INFO,*LPHTTP_VERSION_INFO;
^~~~~~~~~~~~~~~~~
In file included from .\http.cpp:2:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:543:3: note: previous declaration as 'typedef struct HTTP_VERSION_INFO HTTP_VERSION_INFO'
} HTTP_VERSION_INFO, *LPHTTP_VERSION_INFO;
^~~~~~~~~~~~~~~~~
In file included from .\http.cpp:4:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/wininet.h:224:24: error: conflicting declaration 'typedef struct HTTP_VERSION_INFO* LPHTTP_VERSION_INFO'
} HTTP_VERSION_INFO,*LPHTTP_VERSION_INFO;
^~~~~~~~~~~~~~~~~~~
In file included from .\http.cpp:2:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:543:23: note: previous declaration as 'typedef struct HTTP_VERSION_INFO* LPHTTP_VERSION_INFO'
} HTTP_VERSION_INFO, *LPHTTP_VERSION_INFO;
^~~~~~~~~~~~~~~~~~~
In file included from .\http.cpp:4:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/wininet.h:267:5: error: conflicting declaration 'typedef struct URL_COMPONENTSW URL_COMPONENTSW'
} URL_COMPONENTSW,*LPURL_COMPONENTSW;
^~~~~~~~~~~~~~~
In file included from .\http.cpp:2:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:481:24: note: previous declaration as 'typedef struct URL_COMPONENTS URL_COMPONENTSW'
typedef URL_COMPONENTS URL_COMPONENTSW;
^~~~~~~~~~~~~~~
In file included from .\http.cpp:4:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/wininet.h:267:22: error: conflicting declaration 'typedef struct URL_COMPONENTSW* LPURL_COMPONENTSW'
} URL_COMPONENTSW,*LPURL_COMPONENTSW;
^~~~~~~~~~~~~~~~~
In file included from .\http.cpp:2:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:482:26: note: previous declaration as 'typedef struct URL_COMPONENTS* LPURL_COMPONENTSW'
typedef LPURL_COMPONENTS LPURL_COMPONENTSW;
^~~~~~~~~~~~~~~~~
In file included from C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winnt.h:9,
from C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/minwindef.h:163,
from C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/windef.h:8,
from C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/windows.h:69,
from .\http.cpp:3:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/wininet.h:269:3: error: conflicting declaration 'typedef struct URL_COMPONENTSA URL_COMPONENTS'
__MINGW_TYPEDEF_AW(URL_COMPONENTS)
^~~~~~~~~~~~~~~~~~
In file included from .\http.cpp:2:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:480:3: note: previous declaration as 'typedef struct URL_COMPONENTS URL_COMPONENTS'
} URL_COMPONENTS, *LPURL_COMPONENTS;
^~~~~~~~~~~~~~
In file included from C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winnt.h:9,
from C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/minwindef.h:163,
from C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/windef.h:8,
from C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/windows.h:69,
from .\http.cpp:3:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/wininet.h:270:3: error: conflicting declaration 'typedef struct URL_COMPONENTSA* LPURL_COMPONENTS'
__MINGW_TYPEDEF_AW(LPURL_COMPONENTS)
^~~~~~~~~~~~~~~~~~
In file included from .\http.cpp:2:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/winhttp.h:480:20: note: previous declaration as 'typedef struct URL_COMPONENTS* LPURL_COMPONENTS'
} URL_COMPONENTS, *LPURL_COMPONENTS;
^~~~~~~~~~~~~~~~
In file included from .\http.cpp:4:
C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/wininet.h:1629:1: error: expected declaration before '}' token
}
^
发布于 2020-05-25 07:01:15
#pragma comment
用于Visual C++编译器,gcc/g++将忽略它。在用#pragma
:MinGW:-lwinhttp
编译时,可以使用命令行代替-lwinhttp
。
此外,还需要添加#include <windows.h>
。
代码如下:
#include <stdio.h>
#include <windows.h>
#include <winhttp.h>
int main(void) {
// Use WinHttpOpen to obtain a session handle.
WinHttpOpen(L"A WinHTTP Example Program/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
return 0;
}
编译命令如下:
g++ test.cpp -o test.exe -lwinhttp
发布于 2020-08-07 19:30:21
有点晚了,但我的问题解决了!究其原因,主要是图书馆的有序性。我将放在第一行,这确实解决了我的错误:)
https://stackoverflow.com/questions/61986492
复制相似问题