动态调用Dll(未声明的情况下)

作者在 2008-01-08 08:52:20 发布以下内容

一般VB程序调用api的时候都需要事先在程序开头,声明一下需要用到的api,下面的程序演示了一种不需要事先声明,直接调用api的方法.

不过我测试了一下,好像没成功.........

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 Command1_Click()
    On Error Resume Next
    'KPD-Team 1999
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    '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("d:\expmap.dll")
    'retrieve the address of 'SetWindowTextA'
    pa = GetProcAddress(lb, "ExploreMap")
    'Call the SetWindowTextA-function
    pa = CallWindowProc(pa, ByVal 0&, ByVal 0&, ByVal 0&, ByVal 0&)
   
    'unmap the library's address
    FreeLibrary lb
    Me.Caption = pa

End Sub

VB | 阅读 3229 次
文章评论,共2条
xvyifu
2008-02-01 00:41
1
没成功你也写。。。
永夜的极光(作者)
2008-02-14 13:22
2
呃,日志发表后才测试的,然后发现不能成功,估计是我哪里弄错了,所以也就没删
游客请输入验证码