title: Conversion from HGDIOBJ to HBRUSH
body: <p>(This question is asked in the context of Win32API using the g++ compiler).
  I have a trouble with understanding why the following line of code won't work</p>
  
  <pre><code>wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
  </code></pre>
  
  <p>wndclass is an instance of the WNDCLASSEX structure, and the Windows API clearly specifies that
  the type of its member hbrBackground is HBRUSH. Further, HBRUSH is just a typedef for a HANDLE, which in turn is a typedef for void*. Hence, HBRUSH should be of type void*.
  Now, the GetStockObject function's return type is HGDIOBJ, which is also typedefed as a HANDLE, hence a void*.</p>
  
  <p>Windows Data Types
  <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx</a></p>
  
  <p>GetStockObject
  <a href="http://msdn.microsoft.com/en-us/library/dd144925(v=vs.85).aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/dd144925(v=vs.85).aspx</a></p>
  
  <p>WNDCLASSEX
  <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms633577(v=vs.85).aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/windows/desktop/ms633577(v=vs.85).aspx</a></p>
  
  <p>Why then do I get the following error upon compilation:</p>
  
  <pre><code>invalid conversion from 'HGDIOBJ {aka void*}' to 'HBRUSH' [-fpermissive]
  </code></pre>
  
  <p>If I explicitly cast the returned value from GetStockObject it works</p>
  
  <pre><code>wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  </code></pre>
  
  <p>Thank you for any help.</p>