VB自动注册dll
VB写出来的Activex DLL,发布到客户端后,必须注册才能使用,一般使用批处理来实现,比如 regsvr32 d:\project\mydll.dll,实际上我们可以在VB程序内部来自动注册这种Activex DLL。具体代码在下面给出来。
注册DLL,RegDll "dll的绝对路径",True;反注册DLL ,RegDll "dll的绝对路径",False
明晨网络Mingchennet.com整理于2007-3-2,发布于2009-6-12
代码如下
-
Option Explicit
-
-
'========================================
-
'声明作用:注册dll
-
'========================================
-
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 CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lParameter As Long, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
-
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
-
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
-
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
-
-
'========================================
-
'函数名称:RegDll
-
'函数作用:注册dll
-
'========================================
-
Function RegDll(DllPath As String, Action As Boolean) As Boolean
-
On Error GoTo ErrHandle:
-
'Dll载入句柄
-
Dim lLib As Long
-
'Dll注册、反注册入口点
-
Dim lpDLLEntryPoint As Long
-
'线程句柄
-
Dim lpThreadID As Long
-
'线程创建句柄
-
Dim mThread As Long
-
Dim mresult As Long
-
-
lLib = LoadLibrary(DllPath)
-
-
If Action Then
-
lpDLLEntryPoint = GetProcAddress(lLib, "DllRegisterServer")
-
Else
-
lpDLLEntryPoint = GetProcAddress(lLib, "DllUnregisterServer")
-
End If
-
-
mThread = CreateThread(ByVal 0, 0, ByVal lpDLLEntryPoint, ByVal 0, 0, lpThreadID)
-
mresult = WaitForSingleObject(mThread, 10000)
-
CloseHandle mThread
-
-
FreeLibrary lLib
-
RegDll = True
-
-
Exit Function
-
ErrHandle:
-
End Function
文章源自:明晨网络,明晨网络原创,《VB自动注册dll》,http://www.mingchennet.com/tec/code/vb/21.htm
- 上一篇:VB下的INI配置文件读写类模块
- 下一篇:VB下的注册表操作类模块