为何 Call DLL 慢很多, 怎么让他变快呢
为何 Call DLL 慢很多, 如何让他变快呢
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Sub Form_Load
dim w as long
For W = 1 To 1000万转
Call timeGetTime --> 0.22 秒
Next
For W = 1 To 1000万转
Call QQQ --> 0.035 秒
Next
End Sub
Sub QQQ
.....................
End Sub
请问
(1) 为何 Call DLL 慢很多, 是什么原因呢.
(2) 有其他调用方式让他变快吗
------解决思路----------------------
Option Explicit
'模块名称:mdlRegServer
'模块功能:不使用regServer.exe 来注册ActiceX OCX ,DLL
'作者:softboy@263.net 从APIGUIDE整理得来
'更新日期:2003-7-29 7:59:58 PM
'相关模块:
'相关文件:
'预期读者和阅读建议:
'使用方法:
' 注册 RegisterServer Me.hWnd, "c:\somedir\some.ocx", True
' 注消 RegisterServer Me.hWnd, "c:\somedir\some.ocx", False
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 Const ERROR_SUCCESS = &H0
Public 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
'***********************************************************
'*希望能够对你有所帮助!
'***********************************************************
像这这个是一个直接调用DLL的方式 pa = GetProcAddress(lb, "DllRegisterServer"),然后FOr i=1 TO 1000万:call CallWindowProc(pa, hWnd, ByVal 0&, ByVal 0&, ByVal 0&)
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Sub Form_Load
dim w as long
For W = 1 To 1000万转
Call timeGetTime --> 0.22 秒
Next
For W = 1 To 1000万转
Call QQQ --> 0.035 秒
Next
End Sub
Sub QQQ
.....................
End Sub
请问
(1) 为何 Call DLL 慢很多, 是什么原因呢.
(2) 有其他调用方式让他变快吗
------解决思路----------------------
Option Explicit
'模块名称:mdlRegServer
'模块功能:不使用regServer.exe 来注册ActiceX OCX ,DLL
'作者:softboy@263.net 从APIGUIDE整理得来
'更新日期:2003-7-29 7:59:58 PM
'相关模块:
'相关文件:
'预期读者和阅读建议:
'使用方法:
' 注册 RegisterServer Me.hWnd, "c:\somedir\some.ocx", True
' 注消 RegisterServer Me.hWnd, "c:\somedir\some.ocx", False
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 Const ERROR_SUCCESS = &H0
Public 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
'***********************************************************
'*希望能够对你有所帮助!
'***********************************************************
像这这个是一个直接调用DLL的方式 pa = GetProcAddress(lb, "DllRegisterServer"),然后FOr i=1 TO 1000万:call CallWindowProc(pa, hWnd, ByVal 0&, ByVal 0&, ByVal 0&)