title: PNG/JPG file to HBITMAP with GDI+
body: <p>I need to load an image as a HBITMAP in C++ so I can send it to a printer.
  I've tried using <code>Gdiplus::Bitmap::FromFile</code>and then <code>Gdiplus::Bitmap-&gt;GetHBITMAP</code> however the HBITMAP returned is still empty.</p>
  
  <p>I can load .bmp files fine with <code>LoadImage()</code> but this doesn't work with PNG files.</p>
  
  <p>Could anyone point me to the correct way of implementing this to work with .png (and more, if possible) file types?</p>
  
  <p>EDIT: CODE</p>
  
  <pre><code>ZeroMemory(&amp;hBitmap, sizeof(HBITMAP));
  Gdiplus::Bitmap* gpBitmap = Gdiplus::Bitmap::FromFile(L"img.png");
  gpBitmap-&gt;GetHBITMAP(0, &amp;hBitmap);
  </code></pre>
  
  <p>EDIT 2: Solution found</p>
  
  <pre><code>HBITMAP GetHBITMAPFromImageFile(WCHAR* pFilePath)
  {
      GdiplusStartupInput gpStartupInput;
      ULONG_PTR gpToken;
      GdiplusStartup(&amp;gpToken, &amp;gpStartupInput, NULL);
      HBITMAP result = NULL;
      Gdiplus::Bitmap* bitmap = Gdiplus::Bitmap::FromFile(pFilePath, false);
      if (bitmap)
      {
          bitmap-&gt;GetHBITMAP(Color(255, 255, 255), &amp;result);
          delete bitmap;
      }
      GdiplusShutdown(gpToken);
      return result;
  }
  </code></pre>