title: How to get description of winhttp errors using error codes?
body: <p>I am making a program that uses winhttp library. To handle various exceptions, I have created a header file. The error is thrown by using GetLastError() function which is passed to the exception class as DWORD variable. But I want to print the description of error and not just the  error number. I tried using FormatMessage function, its working for error 6 but not for others viz error 12002. I am using it like: </p>
  
  <pre><code>    WinHttpException(DWORD error)
      {
          LPTSTR lpszFunction = "Function";
          LPVOID lpMsgBuf;
          LPVOID lpDisplayBuf;
          DWORD dw = error; 
  
          FormatMessage(
              FORMAT_MESSAGE_ALLOCATE_BUFFER | 
              FORMAT_MESSAGE_FROM_SYSTEM |
              FORMAT_MESSAGE_IGNORE_INSERTS,
              NULL,
              dw,
              MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
              (LPTSTR) &amp;lpMsgBuf,
              0, NULL );
  
          // Display the error message and exit the process
  
          lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, 
              (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR)); 
  
          StringCchPrintf((LPTSTR)lpDisplayBuf, 
              LocalSize(lpDisplayBuf) / sizeof(TCHAR),
              TEXT("%s failed with error %d: %s"), 
              lpszFunction, dw, lpMsgBuf); 
  
          MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK); 
  
          m_message = boost::lexical_cast&lt;std::string&gt;(lpDisplayBuf);
      }
  </code></pre>
  
  <p>I got this code from this Microsoft <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms680582%28v=vs.85%29.aspx" rel="nofollow">link</a>.. Is there any other way to do that? Or what arguments should i use in FormatMessage function to make this work?
  Thanks in advance.</p>