title: C++ Compile problem with WinHttp/Windows SDK
body: <p>Trying to compile a sample http class with the SDK, and getting some strange link errors... I am sure its something to do with a missing option, or directory...</p>
  
  <p>I am no expert in c++ as you can see, but looking for any assistance.</p>
  
  <p>I included my sample class.  I also did install the Windows SDK.  If you need any other information about my setups or anything, please ask.  I'd prefer someone point me to a working WinHttp SDK sample project.</p>
  
  <pre><code>//START OF utils.cpp
  #pragma once
  #include "stdafx.h"
  
  class http
  {
  public:
      http();
      ~http();
  
      std::string getText();
  
  };
  //END OF utils.cpp
  </code></pre>
  
  <hr>
  
  <pre><code>//START OF utils.cpp
  #include "stdafx.h"
  #include "utils.h"
  
  http::http()
  {
  }
  
  http::~http()
  {
  }
  
  std::string http::getText()
  {
      DWORD dwSize = 0;
      DWORD dwDownloaded = 0;
      LPSTR pszOutBuffer;
      BOOL  bResults = FALSE;
      HINTERNET  hSession = NULL, 
          hConnect = NULL,
          hRequest = NULL;
  
      // Use WinHttpOpen to obtain a session handle.
      hSession = WinHttpOpen( L"WinHTTP Example/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.microsoft.com",
          INTERNET_DEFAULT_HTTPS_PORT, 0 );
  
      // Create an HTTP request handle.
      if( hConnect )
          hRequest = WinHttpOpenRequest( hConnect, L"GET", NULL,
          NULL, WINHTTP_NO_REFERER, 
          WINHTTP_DEFAULT_ACCEPT_TYPES, 
          WINHTTP_FLAG_SECURE );
  
      // 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 );
  
      // Keep checking for data until there is nothing left.
      if( bResults )
      {
          do 
          {
              // Check for available data.
              dwSize = 0;
              if( !WinHttpQueryDataAvailable( hRequest, &amp;dwSize ) )
                  printf( "Error %u in WinHttpQueryDataAvailable.\n",
                  GetLastError( ) );
  
              // Allocate space for the buffer.
              pszOutBuffer = new char[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, &amp;dwDownloaded ) )
                      printf( "Error %u in WinHttpReadData.\n", GetLastError( ) );
                  else
                      printf( "%s", pszOutBuffer );
  
                  // Free the memory allocated to the buffer.
                  delete [] pszOutBuffer;
              }
          } while( dwSize &gt; 0 );
      }
  
  
      // 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 "";
  }
  //END OF utils.cpp
  </code></pre>
  
  <hr>
  
  <pre><code>1&gt;------ Build started: Project: winagent, Configuration: Debug Win32 ------
  1&gt;Compiling...
  1&gt;utils.cpp
  1&gt;Linking...
  1&gt;   Creating library C:\winagent\Debug\winagent.lib and object C:\winagent\Debug\winagent.exp
  1&gt;utils.obj : error LNK2019: unresolved external symbol __imp__WinHttpCloseHandle@4 referenced in function "public: class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; __thiscall http::getText(void)" (?getText@http@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
  1&gt;utils.obj : error LNK2019: unresolved external symbol __imp__WinHttpReadData@16 referenced in function "public: class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; __thiscall http::getText(void)" (?getText@http@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
  1&gt;utils.obj : error LNK2019: unresolved external symbol __imp__WinHttpQueryDataAvailable@8 referenced in function "public: class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; __thiscall http::getText(void)" (?getText@http@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
  1&gt;utils.obj : error LNK2019: unresolved external symbol __imp__WinHttpReceiveResponse@8 referenced in function "public: class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; __thiscall http::getText(void)" (?getText@http@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
  1&gt;utils.obj : error LNK2019: unresolved external symbol __imp__WinHttpSendRequest@28 referenced in function "public: class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; __thiscall http::getText(void)" (?getText@http@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
  1&gt;utils.obj : error LNK2019: unresolved external symbol __imp__WinHttpOpenRequest@28 referenced in function "public: class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; __thiscall http::getText(void)" (?getText@http@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
  1&gt;utils.obj : error LNK2019: unresolved external symbol __imp__WinHttpConnect@16 referenced in function "public: class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; __thiscall http::getText(void)" (?getText@http@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
  1&gt;utils.obj : error LNK2019: unresolved external symbol __imp__WinHttpOpen@20 referenced in function "public: class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; __thiscall http::getText(void)" (?getText@http@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
  1&gt;C:\winagent\Debug\winagent.exe : fatal error LNK1120: 8 unresolved externals
  1&gt;Build log was saved at "file://c:\winagent\Debug\BuildLog.htm"
  1&gt;winagent - 9 error(s), 0 warning(s)
  ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
  </code></pre>