一、純DLL資源的制作
打開VC6.0 建立一個基于win32的動态連結庫
下一步中,要選擇A sinmple Dll project
然後加載資源(注意對于超過256色的位圖,VC不能編輯,不過這沒關系)
可以加載位圖、圖示、字元串等,這是加載後的情況
資源添加完畢後,編譯。(最好設為釋出模式)
這樣,一個純資源DLL就編譯完畢了。
二、VB動态調用資源DLL
調用很簡單,源碼如下:
'*************************************************************************
'** 葉帆源碼 CSDN:yefanqiu
'**-----------------------------------------------------------------------
Option Explicit
Private Const IDS_STRING1 As Long = 1
Private Const IDS_STRING2 As Long = 2
Private Const IDS_STRING3 As Long = 3
Private Const IDI_ICON1 As Long = 101
Private Const IDB_BITMAP1 As Long = 102
Private Const IDB_BITMAP2 As Long = 103
Private Const DST_BITMAP = 4
Private Const OBJ_BITMAP = 7
'位圖結構
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
Private Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBQUAD
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 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 Long) As Long
Private Declare Function LoadIcon Lib "user32" Alias "LoadIconA" (ByVal hInstance As Long, ByVal lpIconName As Long) As Long
Private Declare Function GetObjectType Lib "gdi32" (ByVal hgdiobj 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 DrawIcon Lib "user32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Declare Function DrawState Lib "user32" Alias "DrawStateA" (ByVal hDC As Long, ByVal hBrush As Long, ByVal lpDrawStateProc As Long, ByVal lParam As Long, ByVal wParam As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal n3 As Long, ByVal n4 As Long, ByVal un As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
'**函 數 名:LoadRes
'**輸 入:無
'**輸 出:無
'**功能描述:資源加載
'**全局變量:
'**調用子產品:
'**作 者:葉帆
'**日 期:2005-03-15 12:27:34
'**修 改 人:
'**日 期:
'**版 本:V1.0.0
Private Sub LoadRes()
Dim hRes As Long
Dim strData As String
Dim hBmp As Long
Dim hIcon As Long
Dim bitBmp As BITMAPINFO
'加載DLL
hRes = LoadLibrary(Combo1.Text)
'字元串
strData = Space(255)
LoadString hRes, IDS_STRING1, strData, 255
Label1(0).Caption = Trim(strData)
LoadString hRes, IDS_STRING2, strData, 255
Label1(1).Caption = Trim(strData)
LoadString hRes, IDS_STRING3, strData, 255
Label1(2).Caption = Trim(strData)
'位圖
hBmp = LoadBitmap(hRes, IDB_BITMAP1)
If GetObjectType(hBmp) = OBJ_BITMAP Then
GetObject hBmp, Len(bitBmp), bitBmp
DrawState Picture1(0).hDC, 0, ByVal 0, hBmp, 0, 0, 0, bitBmp.bmiHeader.biWidth, bitBmp.bmiHeader.biHeight, DST_BITMAP
End If
'圖示
hIcon = LoadIcon(hRes, IDI_ICON1)
DrawIcon Picture1(1).hDC, 0, 0, hIcon
'釋放資源
DeleteObject hBmp
DeleteObject hIcon
'釋放DLL
FreeLibrary hRes
End Sub
'**函 數 名:Combo1_Click
'**功能描述:更換DLL
'**日 期:2005-03-15 12:28:49
Private Sub Combo1_Click()
LoadRes
'**函 數 名:Form_Load
'**功能描述:初始化
'**日 期:2005-03-15 12:28:58
Private Sub Form_Load()
Combo1.ListIndex = 0
LoadRes
'**函 數 名:Picture1_Paint
'**輸 入:Index(Integer) -
'**功能描述:重新整理
'**日 期:2005-03-15 12:29:03
Private Sub Picture1_Paint(Index As Integer)
運作後的界面:
運作後的界面: