我写了好简单的几行代码,在得到网页内容大小的那行出了问题,我的length字符数组里的数是30400070,本来是3407,可不知道中间怎么多插了个0,结果得到的len是3
h_Internet = InternetOpen( NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
h_openInter = InternetOpenUrl(h_Internet,TEXT("http://www.baidu.com/"),NULL,NULL,NULL,NULL);
dw = sizeof(Length);
HttpQueryInfo(h_openInter,HTTP_QUERY_CONTENT_LENGTH, (LPVOID)Length, &dw, NULL); len = atoi(Length); pBuf = new char[len+1]; InternetReadFile(h_openInter,pBuf,len,&dw);

解决方案 »

  1.   

    lpdwBufferLength 
    Pointer to a variable that contains, on entry, the size in bytes of the buffer pointed to by lpvBuffer. When the function returns successfully, this variable contains the number of bytes of information written to the buffer. In the case of a string, the byte count does not include the string's terminating null character.问题很大啊
    HttpQueryInfo(h_openInter,HTTP_QUERY_CONTENT_LENGTH, (LPVOID)Length, &dw, NULL); 
    MSDN上第4个参数的说明,你填进去的是dw的地址,dw=4,也就是说第3个参数接收buffer的长度是4,但你这样(LPVOID)Length是指向哪里呢?把Length里的内容作为了地址,万幸还没有出错。而且MSDN上说第4个参数the byte count does not include the string's terminating null character,不包括结尾的0,那么4-1=3就这样来的
      

  2.   

    char Length[32]=""; length指向一个32字节的缓冲区啊,dw接受写入缓冲区的字节数啊
    没看明白你写的
      

  3.   

    请看这里http://fronkx.blog.hexun.com/12407600_d.html
      

  4.   

    怎么没次都是读进一个word 而不是一个byte 放进数组里 谁知道为什么啊
      

  5.   

    自己解决了  原来那个buffer要用TCHAR