
Dll returns a Handle to a DIB how can I display in picture box
A handle from VC is treated as a Long in VB, so your declaration should be
Private Declare Function DecodeImage Lib "C:\Time Capsule
Project\Controls\TimeCap" (ByVal sFileName As String) As Long
When you have the handle, you have to select it into a Device Context and
then
BitBlt it to a picturebox. Before you can BitBlt, you first have to get the
bitmap
information to know the width and height.
Here's an example:
Private Declare Function DecodeImage Lib "C:\Time Capsule
Project\Controls\TimeCap" (ByVal sFileName As String) As Long
Private Type BITMAP '14 bytes
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long)
As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal
hObject As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x
As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal
hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long)
As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As
Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal
hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Dim nDC As Long, nBitmap As Long, BitInfo As BITMAP
'Create a device context, compatible with the screen
nDC = CreateCompatibleDC(ByVal 0&)
'use you function to retrieve the DIB's handle
nBitmap = DecodeImage("c:\myfile.ext")
'select the bitmap into the device context
SelectObject nDC, nBitmap
'get the bitmap-information
GetObject nBitmap, Len(BitInfo), BitInfo
'copy the picture from the memory to the picture box
BitBlt Picture1.hdc, 0, 0, BitInfo.bmWidth, BitInfo.bmHeight, nDC, 0, 0,
vbSrcCopy
'if you've set the AutoRedraw-property to True, you should also call
'Picture1.Refresh after you BitBlted the bitmap
'if you don't need your bitmap anymore, you should remove the
'bitmap and the device context from the memory
DeleteDC nDC
DeleteObject nBitmap
Regards,
Pieter Philippaerts
http://www.allapi.net/
Quote:
> Hello Hopefully someone can point me in the correct direction.
> I'm calling a C++ .DLL that when passed a file name will(does) return
> a handle to a device independent bitmap. I have tried many different
> methods of working with this return value but have had no luck. Most
> of the things that I have tried end up with an GPF and a Access
> Violation or an Invalid Procedure or what I assume is a long value
> representing the handle. The DLL function I'm calling works great in
> C++ to put the Image Data into the clipboard. But I can't seem to do
> the same in VB5/6.
> Private Declare Function DecodeImage Lib "C:\Time Capsule
> Project\Controls\TimeCap" (ByVal sFileName As String) As Image (?????)
> this may be(is) incorrect but I know it returns a handle to a dib.
> Any help would be great!
> Thank you.
> Charles Andrews
> Please reply to group
> To Email..
> remove "ca."