CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2001
    Location
    Amsterdam, the Netherlands
    Posts
    8

    Get bitmap resource from DLL



    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 !



  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Get bitmap resource from DLL

    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
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured