LoadLibrary

LoadLibrary

LoadLibrary是計算機語法

基本介紹

  • 外文名:LoadLibrary
  • 備註:計算機語法
  • 返回值註解:不需要,用FreeLibrary函式釋放
  • VB6實例:'KPD-Team 1999
語法,聲明,說明,返回值,VB6實例,

語法

Syntax(C++)
HMODULE WINAPI LoadLibrary( _In_ LPCTSTR lpFileName);

聲明

VB6:
Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
VB.NET
Declare Unicode Function LoadLibrary Lib "kernel32" Alias "LoadLibraryW" (lpLibFileName As String) As IntPtr

說明

載入指定的動態程式庫,並將它映射到當前進程使用的地址空間。一旦載入,即可訪問庫內保存的資源

返回值

Long,成功則返回庫模組的句柄,零表示失敗。會設定GetLastError
參數 類型及說明
lpLibFileName String,指定要載入的動態程式庫的名稱。採用與CreateProcess函式的lpCommandLine參數指定的同樣的搜尋順序
註解
一旦不需要,用FreeLibrary函式釋放DLL

VB6實例

Create a new project and add this code to Form1
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Any, ByVal wParam As Any, ByVal lParam As Any) As Long
Private Sub Form_Load()
On Error Resume Next
'KPD-Team 1999
'We're going to call an API-function, without declaring it!
Dim lb As Long, pa As Long
'map 'user32' into the address space of the calling process.
Lb = LoadLibrary("user32")
'retrieve the address of 'SetWindowTextA'
pa = GetProcAddress(lb, "SetWindowTextA")
'Call the SetWindowTextA-function
CallWindowProc pa, Me.hWnd, "Hello !", ByVal 0&, ByVal 0&
'unmap the library's address
FreeLibrary lb
End Sub

相關詞條

熱門詞條

聯絡我們