title: How much memory should be allocated for the DIB data received from HBITMAP using GetDIBits function?
body: <p>How much memory should be allocated for the DIB data received from HBITMAP using GetDIBits function?</p>
  
  <p>The GetDIBits function is described in MSDN as follow:</p>
  
  <pre><code>int GetDIBits(
    __in     HDC hdc,
    __in     HBITMAP hbmp,
    __in     UINT uStartScan,
    __in     UINT cScanLines,
    __out    LPVOID lpvBits,
    __inout  LPBITMAPINFO lpbi,
    __in     UINT uUsage
  );
  </code></pre>
  
  <p>However, the buffer to receive data lpvBits must be allocated before calling GetDIBits, because GetDIBits doesn't allocate this automatically.</p>
  
  <p>The question is how much memory should be allocated to receive the DIB data? Supposed that the HBITMAP has width&amp;height as Bmp_Width&amp;Bmp_Height; and the bitmap is 32-bit (RGBA).</p>