Click to See Complete Forum and Search --> : Missing overloaded of Bitmap::GetHbitmap????


thegrinch
January 12th, 2007, 12:20 PM
Hi!
I am wondering, why everybody is talking of a Bitmap-method

Bitmap::GetHbitmap(Color, HBITMAP)


I am using VC++ 2003 and have to give a HBITMAP to C-dll.
The only method i could find does not return a HBITMAP:

IntPtr Bitmap::GetHbitmap(Color)

Thanks in advance!

thegrinch

Zaccheus
January 12th, 2007, 02:57 PM
Did you mean this one?


Status GetHBITMAP(const Color &colorBackground, HBITMAP *hbmReturn);


That is from the native (not .net) version of GDI+

thegrinch
January 12th, 2007, 04:15 PM
Yeah!
But there should exist an equivalent to this function?

I just have to get the HBITMAP filled.
I also wonder, why I can't access the fields of a HBITMAP (via intelliSense)...

Kind regards!

thegrinch

Zaccheus
January 12th, 2007, 04:37 PM
HBITMAP is just a handle, there are no methods or properties.

In the .net version, the returned IntPtr is the bitmap handle.

thegrinch
January 13th, 2007, 03:06 AM
Hmm, ok, I understand.
But, please consider the following code:


extern "C" __declspec(dllimport)bool setPicture ( HBITMAP hbitmap );

...

IntPtr h_bitmap_handle = NULL;

h_bitmap_handle = bitmap->GetHbitmap(System::Drawing::Color::Black);

setPicture(h_bitmap_handle);


This (of course) complains with C2664 "cannot convert parameter 1 from 'System::IntPtr' to 'HBITMAP'"

Also casting h_bitmap_handle to HBITMAP does not work, leads to C2440 error.

Any Idea how I can create a HBITMAP from my Bitmap?

Thanks a lot!

Zaccheus
January 13th, 2007, 04:02 AM
Try declaring the external function as follows:


using namespace System::Runtime::InteropServices;

[DllImport("MyModule.dll", CallingConvention = CallingConvention::Cdecl)]
extern "C" System::Byte setPicture(System::IntPtr);


MyModule.dll needs the be replaced by the name of the DLL which contains the setPicture function.
System::Byte is returned instead of bool because setPicture returns a C++ 8bit bool and not a Windows API BOOL.

thegrinch
January 13th, 2007, 12:31 PM
Cool!

Thank you very much

I solved the problem. Everything works now!

Zaccheus
January 13th, 2007, 12:40 PM
You are welcome.
:)