Click to See Complete Forum and Search --> : Get bitmap resource from DLL


The Man
June 15th, 2001, 09:20 AM
I use this subroutine to get a bitmap resource from a DLL. Before I built an only-resource DLL.



private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _
(byval lpLibFileName as string) as Long

private Declare Function LoadBitmap Lib "user32" Alias "LoadBitmapA" _
(byval hInstance as Long, byval lpBitmapName as Long) as Long

Sub GetBitmap(sDllName as string, oPic1 as Object, sBMPName as Long)
Dim tmpDC as Long
Dim objhandle as Long, oldobject as Long
Dim Ret as Long
Dim bmpInfo as BITMAP
Dim lhInst as Long

lhInst = LoadLibrary(sDllName)

If lhInst = 0 then
' error
Exit Sub
End If

oPic1.Picture = LoadPicture()

' Create a memory device context compatible with
' the picture control and load the bitmap.
tmpDC = CreateCompatibleDC(oPic1.hdc)
objhandle = LoadBitmap(lhInst, CLng(sBMPName))
...

End Sub









Second parameter of LoadBitmap function is a long type!
In VC I used LoadBitmap function in this mode :

hBitmap=LoadBitmap(hMod, MAKEINTRESOURCE(resid))

How can I convert an long value to a resource type compatible with the LoadBitmap function in Visual Basic environment ??

Early Thanks !

Clearcode
June 15th, 2001, 10:14 AM
The MAKEINTRESOURCE returns a long value with the value passed in in the bottom 16 bits and the top 16 bits empty.

This can be done in VB by the following:

public Function vbMakeIntResource(byval nRes as Integer) as Long

vbMakeIntResource = CLng(nRes)

End Function




HTH,
D.

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com