Results 1 to 2 of 2

Thread: Bitmaps from DLL

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    6

    Bitmaps from DLL

    Hi,

    I saw thread regarding Bitmaps In DLL.But i face following problem...

    I have the dll which contains only bitmaps, i should not include any class or functions other than that resource file.

    So how to retrive the images from DLL now,
    I am using the following code, but it returns long data type..no idea how to proceed next..

    "LoadBitmap" is API

    Dim hInst As Long, lResult As Long
    Dim Img As Image
    Dim resString As String * 255
    IntLocation = 301
    hInst = LoadLibrary("MyDLL.dll")
    lResult = LoadBitmap(hInst, "301")
    lResult = StrPtr(lResult)
    Picture1.Picture = lResult

    Pls Help me out...


    Thanks
    Harish

  2. #2
    Fanatic Member THEROB's Avatar
    Join Date
    Oct 2000
    Location
    I'm cold and there are wolves after me
    Posts
    575

    Re: Bitmaps from DLL

    Try this:
    VB Code:
    1. Private Type GUID
    2.      Data1 As Long
    3.      Data2 As Integer
    4.      Data3 As Integer
    5.      Data4(7) As Byte
    6. End Type
    7.  
    8. Private Type PicBmp
    9.      Size As Long
    10.      Type As Long
    11.      hBmp As Long
    12.      hPal As Long
    13.      Reserved As Long
    14. End Type
    15.  
    16. Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" _
    17.            (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnHandle As Long, _
    18.            IPic As IPicture) As Long
    19. Private Declare Function LoadBitmap Lib "user32" Alias "LoadBitmapA" _
    20.                (ByVal hInstance As Long, ByVal lpBitmapID As Long) As Long
    21. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    22. Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _
    23.                (ByVal lpLibFileName As String) As Long
    24. Private Declare Function FreeLibrary Lib "kernel32" _
    25.                (ByVal hLibModule As Long) As Long
    26.  
    27. 'Exemplo em SHELL32.DLL com ID 131
    28. Private Function LoadPictureDLL(sResourceFileName As String, _
    29.                         ByVal lResourceId As Long) As Picture
    30.      Dim hInst As Long
    31.      Dim hBmp  As Long
    32.      Dim Pic As PicBmp
    33.      
    34.      Dim IPic As IPicture
    35.      Dim IID_IDispatch As GUID
    36.      Dim lRC As Long
    37.      
    38.      
    39.      hInst = LoadLibrary(sResourceFileName)
    40.      If hInst <> 0 Then
    41.           hBmp = LoadBitmap(hInst, lResourceId)
    42.           If hBmp <> 0 Then
    43.                IID_IDispatch.Data1 = &H20400
    44.                IID_IDispatch.Data4(0) = &HC0
    45.                IID_IDispatch.Data4(7) = &H46
    46.                Pic.Size = Len(Pic)
    47.                Pic.Type = vbPicTypeBitmap
    48.                Pic.hBmp = hBmp
    49.                Pic.hPal = 0
    50.                lRC = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
    51.                If lRC = 0 Then
    52.                     Set LoadPictureDLL = IPic
    53.                     Set IPic = Nothing
    54.                Else
    55.                     Call DeleteObject(hBmp)
    56.                End If
    57.           End If
    58.           FreeLibrary (hInst)
    59.           hInst = 0
    60.      End If
    61. End Function
    62.  
    63.  
    64. Private Sub Command1_Click()
    65.  Set Picture1.Picture = LoadPictureDLL("cards.dll", 1)
    66. End Sub
    My secretary hopes that I will pay her, her landlord hopes that she will produce some rent, the Electricity Board hopes that he will settle their bill, and so on. I find it a wonderfully optimistic way of life. [Dirk Gently]

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