绝对给分

解决方案 »

  1.   

    >如何使用loadlibrary等动态调用dll?最好给例子,谢谢了
    Option Explicit
    '模块名称:mdlRegServer
    '模块功能:不使用regServer.exe 来注册ActiceX OCX ,DLL
    '作者:[email protected] 从APIGUIDE整理得来
    '更新日期:2003-7-29 7:59:58 PM
    '相关模块:
    '相关文件:
    '预期读者和阅读建议:
    '使用方法:
    ' 注册 RegisterServer Me.hWnd, "c:\somedir\some.ocx", True
    ' 注消 RegisterServer Me.hWnd, "c:\somedir\some.ocx", FalsePrivate 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 Const ERROR_SUCCESS = &H0Public Function RegisterServer(hWnd As Long, DllServerPath As String, bRegister As Boolean)
       On Error Resume Next
        '*关键外部调用:FileExist
        If Not mdlUtilities.FileExist(DllServerPath) Then
           MsgBox "Err: Cann't find the path [" & DllServerPath & "] !"
           Exit Function
        End If
        '***************
        Dim lb As Long, pa As Long
        lb = LoadLibrary(DllServerPath)
        If bRegister Then
            pa = GetProcAddress(lb, "DllRegisterServer")
        Else
            pa = GetProcAddress(lb, "DllUnregisterServer")
        End If
        '***************
       If CallWindowProc(pa, hWnd, ByVal 0&, ByVal 0&, ByVal 0&) = ERROR_SUCCESS Then
            MsgBox IIf(bRegister = True, "Registration", "Unregistration") + " Successful"
       Else
            MsgBox IIf(bRegister = True, "Registration", "Unregistration") + " Unsuccessful"
       End If
       '***************
       FreeLibrary lb
    End Function
    '***********************************************************
    '*希望能够对你有所帮助!
    '***********************************************************'*欢迎访问我的网站,给我的作品提宝贵意见!希望和大家交朋友!
    http://www.softboyzhou.com
    '*下载EasyDialog:
    http://www.softboyzhou.com/download/EasyDialog.asp
      

  2.   

    '新建一个标准工程,在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
        '我们可以调用一个api函数,而无需声明它
        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
      

  3.   

    http://www.csdn.net/Develop/Read_Article.asp?Id=18015
      

  4.   

    Option Explicit
    Private Declare Function LoadLibrary Lib "kernel32.dll" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
    Private Declare Function FreeLibrary Lib "kernel32.dll" (ByVal hLibModule As Long) As Long
    Private Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Declare Function GetProcAddress Lib "kernel32.dll" (ByVal hModule As Long, ByVal lpProcName As String) As LongPrivate Sub Command1_Click()
        Dim Modulehwnd As Long, DllFileName As String
        Dim ProcAddr As Long, NameOfProcedure As String
        Dim Result As Long
        
        DllFileName = "C:\Test.dll" & Chr(0)
        Modulehwnd = LoadLibrary(DllFileName)
        
        If Modulehwnd = False Then
            Debug.Print "Error to load this dll or exe"
            Exit Sub
        End If
        
        NameOfProcedure = "DllRegisterServer" & Chr(0)
        
        ProcAddr = GetProcAddress(Modulehwnd, NameOfProcedure)
        
        If ProcAddr = False Then
            Debug.Print "Can't get this address of procedure"
            Exit Sub
        End If
        
        Result = CallWindowProc(ProcAddr, Me.hwnd, 0&, 0&, 0&)
        
        If Result = 0 Then
            Debug.Print "The address of this DLL's exported function is: "; Result
        Else
            Debug.Print "Error to register" & Result
        End If
        
        FreeLibrary DllFileName
        
    End Sub