做过http异步下载文件的请帮忙看一下

原创 2017年01月03日 00:41:25
我用http异步 下载文件时,在下载函数里循环 接收文件数据时没有问题,
do   
{   
INTERNET_BUFFERS InetBuff;   
FillMemory(&InetBuff, sizeof(InetBuff), 0);   
InetBuff.dwStructSize = sizeof(InetBuff);   
InetBuff.lpvBuffer = lpReadBuff;   
InetBuff.dwBufferLength = sizeof(lpReadBuff) - 1;   

if (!InternetReadFileEx(hRequest,   
&InetBuff,   
0, 2))   
{   
if (GetLastError() == ERROR_IO_PENDING)   
{   
 
WaitForSingleObject(hRequestCompleteEvent, INFINITE);   
}   
else   
{   
 
return;   
}   
}   
fwrite(lpReadBuff, sizeof(char),InetBuff.dwBufferLength, pFile);
memset(lpReadBuff, 0, sizeof(lpReadBuff));

if (InetBuff.dwBufferLength == 0)    
bAllDone = TRUE;   

} while (bAllDone == FALSE); 

但是我想在回调函数里处理接收数据,毕竟是异步嘛,数据处理在回调函数里接收比较好
        
        case INTERNET_STATUS_RESPONSE_RECEIVED:   
        {   
                DWORD *dwBytesReceived = (DWORD*)lpStatusInfo;   
                if (*dwBytesReceived == 0)   
                    bAllDone = TRUE;   

                if (pFile)   
                {   
                        if (bAllDone)   
                        {
                                InternetCloseHandle(hRequest);
                                InternetSetStatusCallback( hInstance, NULL);
                                InternetCloseHandle(hInstance);
                                fclose(pFile);
                                return;
                        }
                                fwrite(lpReadBuff, sizeof(char),*dwBytesReceived, pFile);
                        memset(lpReadBuff, 0, sizeof(lpReadBuff));

                        INTERNET_BUFFERS InetBuff;   
                        FillMemory(&InetBuff, sizeof(InetBuff), 0);   
                        InetBuff.dwStructSize = sizeof(InetBuff);   
                        InetBuff.lpvBuffer = lpReadBuff;   
                        InetBuff.dwBufferLength = sizeof(lpReadBuff) - 1;   

                        if (!InternetReadFileEx(hRequest,   
                                &InetBuff,   
                                0, 2))   
                        {   
                                if (GetLastError() == ERROR_IO_PENDING)   
                                {   
                                        WaitForSingleObject(hRequestCompleteEvent, INFINITE);   
                                }   
                                else   
                                {   
                                        return;   
                                }   
                        }   
                } 

但是我在回调函数里接收数据,WaitForSingleObject(hRequestCompleteEvent, INFINITE);   时进入不了INTERNET_STATUS_REQUEST_COMPLETE状态,
但是在主函数里循环 接收就可以进入那个状态,
我的方法有什么问题?求大家解惑!!
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

delphi平台的贪吃蛇游戏,有点小问题,请大家帮忙看一下谢谢

unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,...

delphi平台的贪吃蛇游戏,有点小问题,请大家帮忙看一下谢谢

unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,...

delphi平台的贪吃蛇游戏,有点小问题,请大家帮忙看一下谢谢

unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,...

请各位帮忙看一下,第一个程序为什么不能输出和第二个程序一样的结果?这两个程序只有求最大公约束的代码不同

题目:实现分数的加减乘除。 第一个程序 package hu; public class TestFractory { /** * @param args */ pu...

delphi平台的贪吃蛇游戏,有点小问题,请大家帮忙看一下谢谢

unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,...

delphi平台的贪吃蛇游戏,有点小问题,请大家帮忙看一下谢谢

unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,...

delphi平台的贪吃蛇游戏,有点小问题,请大家帮忙看一下谢谢

unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,...

【求助】一个菜鸟java作业,帮忙看一下错在哪儿,题目是判断回文数

import javax.swing.JOptionPance; public class Number{ public static void main(String args[]) { ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)