To Anyone that wishes to load strings and bitmaps from a DLL into
a Visual Basic application, here's the source, Merry Christmas...

Note: Is project is also being uploaded as FROMDLL.ZIP, along with
the TEST.DLL, that was produced with MSVC++ 


First, this is the definations from FROMDLL.BAS file
----------------------------------------------------
Declare Function LoadLibrary Lib "Kernel" (ByVal lpLibFileName As String) As Integer
Declare Sub FreeLibrary Lib "Kernel" (ByVal hLibModule As Integer)

Declare Function LoadString Lib "User" (ByVal hInstance As Integer, ByVal wID As Integer, ByVal lpBuffer As Any, ByVal nBufferMax As Integer) As Integer

Declare Function LoadBitmap Lib "User" (ByVal hInstance As Integer, ByVal lpBitmapName As Any) As Integer
Declare Function CreateCompatibleDC Lib "GDI" (ByVal hDC As Integer) As Integer
Declare Function SelectObject Lib "GDI" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
Declare Function BitBlt Lib "GDI" (ByVal hDestDC As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal XSrc As Integer, ByVal YSrc As Integer, ByVal dwRop As Long) As Integer
Declare Function DeleteDC Lib "GDI" (ByVal hDC As Integer) As Integer
Declare Function DeleteObject Lib "GDI" (ByVal hObject As Integer) As Integer

' In the test.dll
Declare Function SayHi Lib "TEST.DLL" () As Integer

Global Const SRCCOPY = &HCC0020 ' (DWORD) dest = source

Global DLLID%  ' global handle to the DLL

------------------------------------------------------------
And THIS is the FROMDLL.FRM file, I included the actual form
defination so you can see the controls on the form and their
properties...
------------------------------------------------------------
VERSION 2.00
Begin Form Form1 
   BackColor       =   &H00C0C0C0&
   Caption         =   "From a DLL"
   ClientHeight    =   5700
   ClientLeft      =   1125
   ClientTop       =   2715
   ClientWidth     =   7245
   Height          =   6105
   Icon            =   FROMDLL.FRX:0000
   Left            =   1065
   LinkTopic       =   "Form1"
   ScaleHeight     =   5700
   ScaleWidth      =   7245
   Top             =   2370
   Width           =   7365
   Begin PictureBox Picture2 
      Height          =   2895
      Left            =   3720
      ScaleHeight     =   2865
      ScaleWidth      =   3405
      TabIndex        =   8
      Top             =   2460
      Width           =   3435
   End
   Begin CommandButton btnClearPic 
      Caption         =   "Clear Picture"
      Height          =   495
      Left            =   1980
      TabIndex        =   7
      Top             =   1860
      Width           =   1695
   End
   Begin CommandButton btnPic 
      Caption         =   "Load &Picture"
      Height          =   495
      Left            =   180
      TabIndex        =   6
      Top             =   1860
      Width           =   1695
   End
   Begin PictureBox Picture1 
      AutoRedraw      =   -1  'True  THIS IS VERY IMPORTANT !!!!
      Height          =   2895
      Left            =   180
      ScaleHeight     =   191
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   227
      TabIndex        =   5
      Top             =   2460
      Width           =   3435
   End
   Begin CommandButton btnCallDll 
      Caption         =   "Call DLL"
      Height          =   495
      Left            =   180
      TabIndex        =   4
      Top             =   1200
      Width           =   1695
   End
   Begin CommandButton btnStr2 
      Caption         =   "String 2"
      Height          =   495
      Left            =   1980
      TabIndex        =   3
      Top             =   600
      Width           =   1695
   End
   Begin CommandButton btnStr1 
      Caption         =   "String 1"
      Height          =   495
      Left            =   180
      TabIndex        =   2
      Top             =   600
      Width           =   1695
   End
   Begin TextBox Text1 
      Height          =   285
      Left            =   180
      TabIndex        =   1
      Top             =   180
      Width           =   6975
   End
   Begin CommandButton btnExit 
      Caption         =   "E&xit"
      Height          =   495
      Left            =   5880
      TabIndex        =   0
      Top             =   1200
      Width           =   1215
   End
   Begin Label Label2 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Copied from other Picture"
      Height          =   195
      Left            =   3720
      TabIndex        =   10
      Top             =   5400
      Width           =   2175
   End
   Begin Label Label1 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Loaded from DLL"
      Height          =   195
      Left            =   180
      TabIndex        =   9
      Top             =   5400
      Width           =   1470
   End
End

Option Explicit

' Make a SIMPLE call to the TEST.DLL
Sub btnCallDll_Click ()

Dim r%
r% = SayHi()

End Sub

Sub btnClearPic_Click ()
picture2.Picture = LoadPicture()
picture1.Picture = LoadPicture()
End Sub

Sub btnExit_Click ()
' Make sure to UNLOAD the DLL from memory on exit

FreeLibrary (DLLID%)
End

End Sub

Sub btnPic_Click ()
' The REAL MAGIC !!!

Dim hMyBitmap%, hdcmemory%
Dim r%, dccontrol%, cx%, cy%, pict1%

picture1.ScaleMode = 3

dccontrol% = picture1.hDC
cx% = picture1.ScaleWidth
cy% = picture1.ScaleHeight

' load bitmap from DLL
hMyBitmap% = LoadBitmap(DLLID%, "CPARROW")

' Create context compatible with the picture box
hdcmemory% = CreateCompatibleDC(dccontrol%)
' select bitmap into device context
r% = SelectObject(hdcmemory%, hMyBitmap%)

' Copy it
r% = BitBlt(dccontrol%, 0, 0, cx%, cy%, hdcmemory%, 0, 0, SRCCOPY)

picture1.Picture = picture1.Image ' move presistent image to visible
picture2.Picture = picture1.Picture ' prove it can be moved

r% = DeleteDC(hdcmemory%)      ' delete device context
r% = DeleteObject(hMyBitmap%)  ' delete object (free memory!)

End Sub

Sub btnStr1_Click ()

Dim temp$, r%

temp$ = Space(80) ' allocate space before calling API
r% = LoadString(DLLID%, 1, temp$, Len(temp$))  ' the '1' is the string id
text1 = Trim(temp$)

End Sub

Sub btnStr2_Click ()

Dim temp$, r%

temp$ = Space(80) ' allocate space before calling API
r% = LoadString(DLLID%, 2, temp$, Len(temp$)) ' the '2' is the string id
text1 = Trim(temp$)

End Sub

Sub Form_Load ()
' Load the DLL into memory and get handle to it

DLLID% = LoadLibrary("TEST.DLL")
If DLLID% < 32 Then
    MsgBox "Error loading DLL"
    End
End If

End Sub


-----------------------------------------------------
That's all there is to it...  Hope this help's you
out.

Have fun,
		Edward Lyk
		internet:   EDLYK@delphi.com

