title: Get png file data from a png stored as a Windows resource (c++)
body: <p>I have a PNG resource stored in a Windows exe. I want to load the png resource and create a pointer to the png data that can be written to disk to create a png file. (FWIW, I don't actually create the file at this point; the data is initially written inside another file and saved as a png file later.) This is in an MFC (c++) project, but the solution doesn't need to use MFC.</p>
  <p>I envision a function prototype like this:</p>
  <pre><code>void GetPngFromResource(int iResourceID, VOID* pPngFileData, DWORD* pwPngDataBytes);
  </code></pre>
  <p>I see that ::LoadBitmap(), ::LoadImage() and CImage::LoadFromResource() don't support png resource loading. When I do attempt to use LoadImage(), GetLastError() reports &quot;The specified resource name cannot be found in the image file&quot; (error 1814):</p>
  <pre><code>HBITMAP hBitmapImage = (HBITMAP)::LoadImage(::GetModuleHandle(0), MAKEINTRESOURCE(iResourceID), IMAGE_BITMAP, 0, 0, 0);
  </code></pre>
  <p>I know the resource exists, because I can get a handle to it using FindResource() (although I don't know how, or whether it is possible, to get the png file data from the HRSCR handle):</p>
  <pre><code>HRSCR h = FindResource(HINST_THISCOMPONENT, MAKEINTRESOURCE(iResourceID), L&quot;PNG&quot;);
  </code></pre>
  <p>I have seen examples that create an HBITMAP from a png resource using gdi+, but I need to end up with png file data.</p>
  <p>Thanks!</p>