Windows Develop Bookmark and Share   
 index > Windows Forms General > Bitmap.GetHBitmap() returns invalid handle
 

Bitmap.GetHBitmap() returns invalid handle

I need to access a managed bitmap (header,info,pixels) from unmanaged code but the HBITMAP I get back from Bitmap.GetHbitmap appears to be invalid.  At least that is the error I get when I call GlobalLock() on the HBITMAP.  Any ideas as to how you are supposed to use the HBITMAP that is returned?
Keith Hill  Saturday, September 03, 2005 1:21 AM
You don't provide any information on how you are marshaling the data. I'm assuming that you are using Interop, but, we don't know if you are using COM, or sending the data to another process, or what. I'm also assuming that you understand the defuault marshaling behavior of unmanaged types to .NET data types provided by the Interop Marshaler.
The solution may be just as simple as using the MarshalAsAttribute. Maybe this will help: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimeinteropservicesmarshalasattributeclasstopic.asp
ursus zeta  Sunday, September 04, 2005 7:38 PM
I haven't marshalled anything yet except for whatever IJW does in managed C++.  I'm just trying to figure out how to use System.Drawing.Bitmap to load JPG/GIF/PNG files and then copy the resulting bitmap data (colors, data, etc) into a custom, unmanaged structure which essentially mimics a windows bitmap structure.  We are trying to replace LeadTools libraries with the .NET image support.

I haven't found any examples showing how you can take the HBITMAP from Bitmap.GetHbitmap() and retrieve a pointer to BITMAP structure.
Keith Hill  Wednesday, September 07, 2005 8:56 PM

Also the docs don't say if the GDI bitmap that is created by GetHbitmap is a DIB or a DDB.  Anyone know which it is?

Keith Hill  Wednesday, September 07, 2005 9:36 PM

You can use google to search for other answers

Custom Search

More Threads

• ListView control and Key Strokes
• Look only in subfolders??
• MenuStrip sub items need to be dimmed (disabled)....
• Change UI Culture after Usercontrol or Form is loaded and displayed
• Dock a form on the desktop in C#
• Attaching a file
• List<> from one application to another - how to ... ?
• Use Microsoft Office Outlook in Application
• (.NET2) owner drawn treeview itemwidth
• IP Address