+// otherwise VC++ would give here:
+// "local variable 'bi' may be used without having been initialized"
+// even though in fact it may not
+#ifdef __VISUALC__
+ #pragma warning(disable:4701)
+#endif // __VISUALC__
+
+size_t wxConvertBitmapToDIB(BITMAPINFO *pbi, const wxBitmap& bitmap)
+{
+ // shouldn't be selected into a DC or GetDIBits() would fail
+ wxASSERT_MSG( !bitmap.GetSelectedInto(),
+ wxT("can't copy bitmap selected into wxMemoryDC") );
+
+ HBITMAP hbmp = (HBITMAP)bitmap.GetHBITMAP();
+
+ BITMAPINFO bi;
+
+ // first get the info
+ ScreenHDC hdc;
+ if ( !GetDIBits(hdc, hbmp, 0, 0, NULL, pbi ? pbi : &bi, DIB_RGB_COLORS) )
+ {
+ wxLogLastError("GetDIBits(NULL)");
+
+ return 0;
+ }
+
+ if ( !pbi )
+ {
+ // we were only asked for size needed for the buffer, not to actually
+ // copy the data
+ return sizeof(BITMAPINFO) + bi.bmiHeader.biSizeImage;
+ }
+
+ // and now copy the bits
+ if ( !GetDIBits(hdc, hbmp, 0, pbi->bmiHeader.biHeight, pbi + 1,
+ pbi, DIB_RGB_COLORS) )
+ {
+ wxLogLastError("GetDIBits");
+
+ return 0;
+ }
+
+ return sizeof(BITMAPINFO) + pbi->bmiHeader.biSizeImage;
+}
+
+#ifdef __VISUALC__
+ #pragma warning(default:4701)
+#endif // __VISUALC__
+
+wxBitmap wxConvertDIBToBitmap(const BITMAPINFO *pbmi)
+{
+ // here we get BITMAPINFO struct followed by the actual bitmap bits and
+ // BITMAPINFO starts with BITMAPINFOHEADER followed by colour info
+ const BITMAPINFOHEADER *pbmih = &pbmi->bmiHeader;
+
+ ScreenHDC hdc;
+ HBITMAP hbmp = CreateDIBitmap(hdc, pbmih, CBM_INIT,
+ pbmi + 1, pbmi, DIB_RGB_COLORS);
+ if ( !hbmp )
+ {
+ wxLogLastError("CreateDIBitmap");
+ }
+
+ wxBitmap bitmap(pbmih->biWidth, pbmih->biHeight, pbmih->biBitCount);
+ bitmap.SetHBITMAP((WXHBITMAP)hbmp);
+
+ return bitmap;
+}
+