I see now that you are discarding the bitmap before calling GetBitmapData: this is clearly wrong and you should get an error in that function. Try calling GetBitmapData before discarding the bitmap, but consider that what I wrote before is still valid. Also, you should consider adding some error checking to the code: the function returns a meaninful, negative code in case of error.
Array of RGB color values, or NULL if pixelDepth is greater
If pixelDepth is 8 or less, the
bits array contains indices into the
colorTable array. The number of entries in the
colorTable array must equal 2n, where
n is the value of the pixelDepth parameter.
pixelDepth is greater than 8, the colorTable
parameter is not used. The bits array contains actual RGB color
values rather than indices into the colorTable array.