2011-01-25 28 views
5

Tôi có một vấn đề lớn. Tôi đang cố gắng sử dụng WinHttp để tải về tập tin với C + + và tôi đang sử dụng Visual Studio 2010 để làm điều này.C++ 307 Lỗi khi cố gắng đưa winhttp.h vào phòng thu trực quan 2010

Vấn đề của tôi là chương trình không được biên dịch vì được tạo 307 lỗi, tất cả tham chiếu đến winhttp.h. Tôi đề cập đến rằng tôi đã bao gồm tập tin đó. Điều gì có thể là vấn đề? Cảm ơn!

Có một số:

------ 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' 

Bây giờ tôi có một vấn đề khác. Đây là mã của tôi:

#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; 
} 

Và kết quả là:

------ 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 [email protected] referenced in function _main 
a.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
a.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
a.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
a.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
a.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
a.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
a.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol [email protected] 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 ========== 

gì bây giờ có thể là vấn đề? Tôi đang cố gắng 2 ngày để tạo một đoạn chương trình để tải xuống một tệp từ một URL nhất định. Nó khiến tôi điên lên! Làm ơn giúp tôi!

+0

đăng một số mã .. cũng cung cấp cho chúng tôi một số lỗi, tôi đoán hầu hết trong số chúng đều giống nhau. –

+0

Bạn có thể đăng toàn bộ thông báo lỗi không? – peoro

+0

Đăng toàn bộ khối '# include'. Có thể một số phụ thuộc bị thiếu (như 'windows.h' hoặc thứ gì đó). – detunized

Trả lời

7

Thêm #include <windows.h> trước #include <winhttp.h>.

Các vấn đề liên quan