0

I'm building a dll in C++ to be imported into a VB project. The dll exposes a function that will extract the preview image of a specified document through the Win Shell, and then writes it into a buffer to be used by the VB app.

So far, I'm able to get the HBITMAP handle without issue. I was also able to extract the bitmap data using the GetBitmapBits function. However, this will not work as the object that requires the bit data needs it to be in a device independent format.

I've read that GetDiBits is the function to use for this purpose, but I'm having a hard time figuring out how to call the function successfully.

What device context should I be using? Also, how can I ensure that it writes out the data in device independent format?

Thanks in advance.

JString
  • 1
  • 1
  • So, I made some progress on this project. I found a secondary help document about the GetDiBits function (http://support.microsoft.com/kb/74601). The api documentation did not explain at all that there is a check list that is performed on the header structure. So now that that is out of the way, I was able to execute the function successfully and extract some bitmap data. – JString Nov 22 '11 at 00:11
  • Now the problem I have is apparently the device context or something else. I am testing my code with a 100x100 pixel image with 24-bit colors. The size of the data extracted using GetDiBits was exactly what was expected for an image of that size. However, a DIB is supposed to have extra data such as headers and what not so that it can be passed between devices. So perhaps I am not even using the correct function for this? As a reminder, I need to pass the DIB data to an object in a vb project. – JString Nov 22 '11 at 00:15

1 Answers1

0

If your HBITMAP references a device dependent bitmap, and you need device independent bits, you have to convert them. Try creating a CImage and call the BitBlt method to put device independent bits in it.

Windows programmer
  • 7,871
  • 1
  • 22
  • 23