尝试在 Visual Studio 2010 中包含 winhttp.h 时出现 C++ 307 错误

2024-01-06

我有一个很大的问题。我正在尝试使用 WinHttp 通过 C++ 下载文件,并且我正在使用 Visual Studio 2010 来执行此操作。

我的问题是程序无法编译,因为生成了 307 错误,所有错误都指的是winhttp.h。我提到我已经包含了该文件。可能是什么问题呢?谢谢!

有一些:

------ Build started: Project: a, Configuration: Debug Win32 ------

  b. Cpp

  a. Cpp

c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(50): error C2146: 
Syntax error: missing ';' before identifier 'HINTERNET'

c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(50): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(50): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(51): error C2143: syntax error: missing ';' before '*'

c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(51): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(51): error C2378: 'HINTERNET': redefinition; symbol cannot be overloaded with a typedef

          c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(50): see declaration of 'HINTERNET'


c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(51): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(53): error C2146: syntax error: missing ';' before identifier 'INTERNET_PORT'

c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(53): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(53): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(54): error C2143: syntax error: missing ';' before '*'
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(54): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(54): error C2378: 'INTERNET_PORT': redefinition; symbol cannot be overloaded with a typedef
          c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(53): see declaration of 'INTERNET_PORT'
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(54): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(95): error C2146: syntax error: missing ';' before identifier 'dwResult'
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(95): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(95): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(96): error C2146: syntax error: missing ';' before identifier 'dwError'
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(96): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(96): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(107): error C2146: syntax error: missing ';' before identifier 'dwMajorVersion'
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(107): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(107): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(108): error C2146: syntax error: missing ';' before identifier 'dwMinorVersion'
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(108): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(108): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(144): error C2146: syntax error: missing ';' before identifier 'dwStructSize'
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(144): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(144): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c: \program files (x86)\microsoft sdks\windows\v7.0a\include\winhttp. H(145): error C2146: syntax error: missing ';' before identifier 'lpszScheme'

现在我有另一个问题。这是我的代码:

#include <windows.h>
#include <winhttp.h>
#include <stdio.h>
#include <iostream>
using namespace std;
#include <string.h>

int main()
{
    DWORD dwSize = 0;
    DWORD dwDownloaded = 0;
    LPBYTE pszOutBuffer;
    BOOL bResults = FALSE;
    HINTERNET hSession = NULL, hConnect = NULL, hRequest = NULL;

// Use WinHttpOpen to obtain a session handle.
hSession = WinHttpOpen( L"Internet Explorer example", 
    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.my-new-gadget.com",
    INTERNET_DEFAULT_HTTPS_PORT, 0 );

// Create an HTTP request handle.
if( hConnect )
    hRequest = WinHttpOpenRequest( hConnect, L"GET", L"index.php",
    NULL, WINHTTP_NO_REFERER, 
    NULL, NULL);

// Send a request.
if( hRequest )
    bResults = WinHttpSendRequest( hRequest,
    WINHTTP_NO_ADDITIONAL_HEADERS, 0,
    WINHTTP_NO_REQUEST_DATA, 0, 
    0, 0 );

// End the request.
if( bResults )
    bResults = WinHttpReceiveResponse( hRequest, NULL );

HANDLE hFile = CreateFile("D:\\index.php", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

if (bResults)
{
    do     
    {        
        // Check for available data.        
        dwSize = 0;        
        if (!WinHttpQueryDataAvailable( hRequest, &dwSize))
            printf( "Error %u in WinHttpQueryDataAvailable.\n", GetLastError());        
        // Allocate space for the buffer.        
        pszOutBuffer = new byte[dwSize+1];        
        if (!pszOutBuffer)        
        {            
            printf("Out of memory\n");            
            dwSize=0;        
        }        
        else        
        {            
            // Read the Data.            
            ZeroMemory(pszOutBuffer, dwSize+1);            
            if (!WinHttpReadData( hRequest, (LPVOID)pszOutBuffer, dwSize, &dwDownloaded))                
            {                
                printf( "Error %u in WinHttpReadData.\n", GetLastError());                
            }            
            else                
            {                        
                //printf("%s", pszOutBuffer); 
                DWORD wmWritten;
                bool fr = WriteFile(hFile, pszOutBuffer, dwSize, &wmWritten, NULL);
                int n = GetLastError();              
            }            
            // Free the memory allocated to the buffer.            
            delete [] pszOutBuffer;        
        }    
    } while (dwSize>0);
}

CloseHandle(hFile);
// Report any errors.
if (!bResults)    
    printf("Error %d has occurred.\n",GetLastError());
// Close any open handles.
if (hRequest) WinHttpCloseHandle(hRequest);
if (hConnect) WinHttpCloseHandle(hConnect);
if (hSession) WinHttpCloseHandle(hSession);

return 0;
}

输出是:

------ Build started: Project: a, Configuration: Debug Win32 ------
  a.cpp
c:\users\admin\documents\visual studio 2010\projects\a\a\a.cpp(73): warning C4800: 'BOOL' : forcing value to bool 'true' or 'false' (performance warning)
a.obj : error LNK2019: unresolved external symbol __imp__WinHttpCloseHandle@4 referenced in function _main
a.obj : error LNK2019: unresolved external symbol __imp__WinHttpReadData@16 referenced in function _main
a.obj : error LNK2019: unresolved external symbol __imp__WinHttpQueryDataAvailable@8 referenced in function _main
a.obj : error LNK2019: unresolved external symbol __imp__WinHttpReceiveResponse@8 referenced in function _main
a.obj : error LNK2019: unresolved external symbol __imp__WinHttpSendRequest@28 referenced in function _main
a.obj : error LNK2019: unresolved external symbol __imp__WinHttpOpenRequest@28 referenced in function _main
a.obj : error LNK2019: unresolved external symbol __imp__WinHttpConnect@16 referenced in function _main
a.obj : error LNK2019: unresolved external symbol __imp__WinHttpOpen@20 referenced in function _main
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
c:\users\admin\documents\visual studio 2010\Projects\a\Debug\a.exe : fatal error LNK1120: 9 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

现在可能出现什么问题?我花了 2 天的时间尝试制作一个程序来从给定的 URL 下载文件。这让我疯狂!请帮我!


Add #include <windows.h> before #include <winhttp.h>.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

尝试在 Visual Studio 2010 中包含 winhttp.h 时出现 C++ 307 错误 的相关文章

随机推荐

  • 如何格式化来自 MongoDB 的日期?

    我正在使用 Jade 从 Express js 中呈现我的视图 我正在 MongoDB 中保存文档并使用 Mongoose 访问我的文档 我正在保存创建新文档时创建的默认日期 并将该日期创建属性返回到需要格式化的视图 MongoDB 中存储
  • jquery ui 可调整大小的自定义句柄错误

    我试图让自定义句柄与 jquery ui 可调整大小的小部件一起使用 但是当我使用handles 选项将 jquery 引用传递给另一个元素时 它失败了 从我从文档和网络上的其他示例中读到的内容来看 这应该可以正常工作 div class
  • 具有代理支持的 python webkit

    我正在编写一个用于抓取网页的 python 脚本 我创建了一个 webkit webview 对象并使用 open 方法来加载 url 但我想通过代理加载网址 我怎样才能做到这一点 如何将 webkit 与 proxy 集成 哪个 webk
  • 退出自定义 Sails 1 和 Actions 2

    如果我想使用操作 2 在 sails 1 中返回带有状态代码和错误消息的错误的输出 该怎么办 EX exits notFound description not found responseType notFound 怎样才能退出呢 例如
  • 写入 Hadoop 中 HDFS 中的文件

    我一直在寻找一个磁盘密集型 Hadoop 应用程序来测试 Hadoop 中的 I O 活动 但我找不到任何此类应用程序可以使磁盘利用率保持在上述水平 例如 50 或者某些此类应用程序实际上使磁盘保持繁忙 我尝试了 randomwriter
  • 为什么编译器在 N 字节边界上对齐 N 字节数据类型?

    我不明白为什么编译器在 4 字节边界上对齐 int 在 2 字节边界上对齐 Short 在 1 字节边界上对齐 char 据我了解 如果处理器的数据总线宽度是 4 字节 则从不是 4 的倍数的地址读取 int 需要 2 个内存读取周期 那么
  • 导入 ChatKit(即私有框架)或以某种方式使用 CKDBMessage

    首先 我知道私有框架 API 不会让我进入 AppStore 这仅供私人使用 研究 我无法编译我的项目ChatKit framework 基本上我需要以某种方式初始化CKDBMessage对象并从中获取东西 The first我尝试的方法是
  • 查找 STL 队列中是否已存在某个项目

    我正在使用 STL 队列在图上实现 BFS 广度优先搜索 如果队列中不存在该节点 我需要将其推送到队列中 然而 STL队列确实不允许迭代其元素 http www sgi com tech stl queue html 2因此我无法使用 ST
  • 删除表中的所有外键

    我有这个脚本可以在 sql server 2005 中运行 t sql scriptlet to drop all constraints on a table DECLARE database nvarchar 50 DECLARE ta
  • MVVM - 如何将视图模型绑定到视图

    并提前感谢您的指导 我是 MVVM 的新手 我一直通过文章学习 我想我已经走了很远了 但有一件事似乎让我忽略了 我如何 不使用后面代码中的代码 自动绑定到我想要的视图 据我了解 如果做得正确 这就是模式应该如何工作 我可以使用主窗口 xam
  • 有没有办法使用 React-Router v6 设置默认路由

    我只是找不到用react router v6 设置默认路由的方法 是因为现在编程不好了吗 有人能告诉我为什么吗 提前致谢 Rafael 如果我正确理解您关于 默认 路线的问题 那么我将其解释为以下之一 Use an index route
  • 进程可以在其虚拟内存的任何地址上读/写吗?

    操作系统中的进程有自己的虚拟地址空间 比如说 我在 C 程序中使用 malloc 函数调用分配一些动态内存 并从它返回的地址中减去一些正值 比如 1000 现在 我尝试读取该位置上写的内容 这应该没问题 但是写入该位置怎么样 虚拟地址空间也
  • 正则表达式将字符串与可选条件相匹配[重复]

    这个问题在这里已经有答案了 可能的重复 如何在 Ruby 中使正则表达式的一部分成为可选 https stackoverflow com questions 5239883 how do i make part of a regular e
  • 合并python中的字典列表

    我有 python 中的字典 格式如下 dict1 Name a value 20 Name b value 10 Name c value 15 我想要输出类似这样的内容 dict2 a 20 b 10 c 15 怎么做 我认为你可以用
  • 计算相对于当前行匹配条件的行数

    我有一个像这样构造的数据框 但它实际上有大约 400k 行 library data table df lt fread id start end 174095 2018 12 19 2018 12 31 227156 2018 12 19
  • Dragonfly Gem 与 ImageMagick 和 Passenger

    我在让蜻蜓宝石与乘客很好地配合时遇到了一些问题 Passenger 似乎没有使用当前的 PATH 因此它找不到转换二进制文件 我给蜻蜓添加了一些配置 这似乎解决了这个问题 require dragonfly rails images Dra
  • 解决依赖关系时Maven错误

    我是 Maven 新手 正在尝试建立我的第一个POMs 我的应用程序将使用 EhCache 进行缓存 前往 Maven Central Repo 链接here http mvnrepository com artifact net sf e
  • 状态 Monad 的传播

    我有以下函数用于在游戏世界的 图形 的 边缘 行走 它改变了世界的状态 特别是玩家的位置 我还需要报告一条消息 提醒玩家位置发生变化 所以我可以返回一个 message newWorld 元组 或者我可以使用 State monad 对吧
  • 使用 RabbitMQ 的 SimpMessagingTemplate.convertAndSend 工作速度非常慢

    我正在使用 spring STOMP over Websocket 和 RabbitMQ 一切正常 但 simpMessagingTemplate convertAndSend 工作速度非常慢 调用可能需要 2 10 秒 同步 阻塞线程 能
  • 尝试在 Visual Studio 2010 中包含 winhttp.h 时出现 C++ 307 错误

    我有一个很大的问题 我正在尝试使用 WinHttp 通过 C 下载文件 并且我正在使用 Visual Studio 2010 来执行此操作 我的问题是程序无法编译 因为生成了 307 错误 所有错误都指的是winhttp h 我提到我已经包