How to get hBitmap Handle from Picture

I have a picture object and I need to pass it to a library that has the following method:

Public Sub ReadFromBitmap( ByVal hBitmap As Long, ByVal hPalette As Long )

Parameters
hBitmap
Handle of HBITMAP object
hPalette
Handle of Palette (optional)

Any ideas?

if you have GDI plus off, the picture.handle is a HBITMAP.

There does not seem to be a picture.handle property.

Look into WFS.

There is

Declare Sub GetObjectA Lib "GDI32" ( hBitmap as Integer, size as Integer, struct as Ptr )

And a Private Function HBITMAPFromPicture(p as Picture) As Integer that provides the hBitmap.

You can probably reuse that code :slight_smile:

it’s CopyOSHandle:
http://documentation.xojo.com/index.php/Picture.CopyOSHandle

[quote=136918:@Christian Schmitz]it’s CopyOSHandle:
http://documentation.xojo.com/index.php/Picture.CopyOSHandle[/quote]

The problem is that CopyOSHandle is a pointer, when the function the OP has expects an integer (long in Microsoft parlance).

The pointer can be cast to an integer to be passed to the declare.

Sorry to ask, but after reading through the documentation, I did not find any example about casting a pointer to an integer. Would you please show me ?

Thank you.

I don’t know if this is correct. Could you create a 4 byte long memory block with the pointer and then retrieve the value?

Something like (untested):

Dim mb as New MemoryBlock(4) mb=myPointer //I am not sure about this step, but there seems to be some implicit conversion between MB and Ptr MyInteger=mb.Int32Value(0)

Julen

you can simply use Integer cast. Integer§

How do you actually write the code ?

dim p as ptr // some pointer
dim n as integer = integer§

[quote=137047:@Christian Schmitz]dim p as ptr // some pointer
dim n as integer = integer§[/quote]

Great. Thank you so much Christian :slight_smile: