Newsgroup: it.comp.lang.visual-basic
Titolo: Utilizzo DLL per reperire bitmap

Ciao a tutto il ng.,
Programma in Vb5 con sp3.
Ho una dll (dove ho inserito,stringhe,bitmap e icone da utilizzare nel mio
programma in vb).
La lettura delle stringhe riesco a farla corettamente mentre le bitmap o le
icone  riesco a reperirle dalla dll, il programma non va in errore (ho
notato che "hLoadedbitmap" e "hIcon" sono uguali a 0) .
Io utilizzo il codice seguente:
'Structures Declaration
Private Type BITMAP
    bmType As Long
    bmWidth As Long
    bmHeight As Long
    bmWidthBytes As Long
    bmPlanes As Integer
    bmBitsPixel As Integer
    bmBits As Long
End Type
'Constant Declaration
Private Const SRCCOPY = &HCC0020
'API Function Declaration
Private Declare Function LoadString Lib "user32" Alias "LoadStringA" (ByVal
hInstance As Long, ByVal wID As Long, ByVal lpBuffer As String, ByVal
nBufferMax As Long) As Long
Private Declare Function LoadBitmap Lib "user32" Alias "LoadBitmapA" (ByVal
hInstance As Long, ByVal lpBitmapName As String) As Long
Private Declare Function LoadIcon Lib "user32" Alias "LoadIconA" (ByVal
hInstance As Long, ByVal lpIconName As String) As Long
Private Declare Function DrawIcon Lib "user32" (ByVal hDC As Long, ByVal x
As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA"
(ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule 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
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
**Lettura Icone****
Public Sub DrawDLLIcon(DLLPath As String, IconDesc As String, hDC As Long,
Optional dstX As Long = 0, Optional dstY As Long = 0)
    Dim hLibInst As Long
    Dim hIcon As Long
    hLibInst = LoadLibrary(DLLPath)
    hIcon = LoadIcon(hLibInst, IconDesc)
    Call DrawIcon(hDC, dstX, dstY, hIcon)
    Call FreeLibrary(hLibInst)
End Sub
**Lettura Bitmap*****
Public Sub DrawDLLBitmap(DLLPath As String, PicDesc As String, hDC As Long,
Optional dstX As Long = 0, Optional dstY As Long = 0)
    Dim hLibInst As Long
    Dim hdcMemory As Long
    Dim hLoadedbitmap As Long
    Dim hOldBitmap As Long
    Dim bmpInfo As BITMAP
    hLibInst = LoadLibrary(DLLPath)
    hLoadedbitmap = LoadBitmap(hLibInst, PicDesc)
    Call GetObject(hLoadedbitmap, Len(bmpInfo), bmpInfo)
    hdcMemory = CreateCompatibleDC(hDC)
    hOldBitmap = SelectObject(hdcMemory, hLoadedbitmap)
    Call BitBlt(hDC, dstX, dstY, bmpInfo.bmWidth, bmpInfo.bmHeight,
hdcMemory, 0, 0, SRCCOPY)
    Call SelectObject(hdcMemory, hOldBitmap)
    Call DeleteObject(hLoadedbitmap)
    Call DeleteDC(hdcMemory)
    Call FreeLibrary(hLibInst)
End Sub
**Lettura Stringhe*** 'ok' funziona
Public Function LoadDLLString(DLLPath As String, StrNum As Long) As String
    Dim hLibInst As Long
    Dim posTemp As Integer
    hLibInst = LoadLibrary(DLLPath)
    Call LoadString(hLibInst, StrNum, strTemp, Len(strTemp))
    posTemp = InStr(strTemp, Chr$(0))
    LoadDLLString = Left$(strTemp, posTemp - 1)
    FreeLibrary (hLibInst)
End Function
Qualcuno sa dirmi cosa sbaglio, oppure ha un modo migliore per estrappolare
i dati dalla dll.
Mille grazie a tutti.
Ciao.
Luca Coraini

 ha scritto nel messaggio
news:95m369$43s$1...@news.IT.net...

Forse stasera mi ripeto, ma non era più semplice usare un file di risorse?
Ciao VB

hInstance As Long, ByVal lpIconName As String) As Long
E' possibile che tu passi il numero dell' icona invece del nome ?
Se cosi' fosse, dovresti cambiare la dichiarazione cosi':
Private Declare Function LoadIconLong Lib "user32" Alias "LoadIconA" (ByVal
hInstance As Long, ByVal lpIconName As Long) As Long
...(...)...
Ciao
Aldo

 ha scritto nel messaggio
news:95n8rk$hkd4e$6...@ID-56381.news.dfncis.de...
