http://www.zjol.com.cn/vbbible/software/program/vbapi/LoadLibrary.htmLoadLibrary VB声明 Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long 说明 载入指定的动态链接库,并将它映射到当前进程使用的地址空间。一旦载入,即可访问库内保存的资源 返回值 Long,如执行成功,则返回库模块的句柄;零表示失败。会设置GetLastError 参数表 参数 类型及说明 lpLibFileName String,指定要载入的动态链接库的名称。采用与CreateProcess函数的lpCommandLine参数指定的同样的搜索顺序 注解 一旦不再需要,记住用FreeLibrary函数释放DLL。Windows 会跟踪了解一个DLL已装载了多少次。除非模块的使用计数减至零,否则不会在内存中实际撤消对DLL的映射
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 'URL: http://www.allapi.net/ 'E-Mail: [email protected] '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
如果我这个myfunc有四个参数,比如(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long),那么用CallWindowProc调用时怎么传递这4个参数呢?
我看到他们说的还要LoadLibrary,GetProcAddress,CallWindowProc什么的是什么意思呀?
Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
说明
载入指定的动态链接库,并将它映射到当前进程使用的地址空间。一旦载入,即可访问库内保存的资源
返回值
Long,如执行成功,则返回库模块的句柄;零表示失败。会设置GetLastError
参数表
参数 类型及说明
lpLibFileName String,指定要载入的动态链接库的名称。采用与CreateProcess函数的lpCommandLine参数指定的同样的搜索顺序
注解
一旦不再需要,记住用FreeLibrary函数释放DLL。Windows 会跟踪了解一个DLL已装载了多少次。除非模块的使用计数减至零,否则不会在内存中实际撤消对DLL的映射
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
'URL: http://www.allapi.net/
'E-Mail: [email protected]
'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