做了个自动注册OCX小程序。不知道有没有哪位高人给看一下,有没有不到之处
注册OCX文件小程序源码.rar
(618.11 KB)
程序代码:
Private Sub Command1_Click() On Error Resume Next '注册 If RegSvr32("c:\windows\system32\Abutton.ocx", False) = False Or RegSvr32("c:\windows\SysWOW64\Abutton.ocx", False) = False Then RegSvr32 App.Path & "\Abutton.ocx", False End If End Sub
Public Function RegSvr32(ByVal filename As String, bUnReg As Boolean) As Boolean
Dim lLib As Long
Dim lProcAddress As Long
Dim lThreadID As Long
Dim lSuccess As Long
Dim lExitCode As Long
Dim lThread As Long
Dim bAns As Boolean
Dim sPurpose As String
sPurpose = IIf(bUnReg, "DllUnregisterServer", "DllRegisterServer")
If Dir(filename) = "" Then Exit Function
lLib = LoadLibraryRegister(filename)
'载入文件
If lLib = 0 Then Exit Function
lProcAddress = GetProcAddressRegister(lLib, sPurpose)
If lProcAddress = 0 Then
'不是ActiveX控件
FreeLibraryRegister lLib
Exit Function
Else
lThread = CreateThreadForRegister(ByVal 0&, 0&, ByVal lProcAddress, ByVal 0&, 0&, lThread)
If lThread Then
lSuccess = (WaitForSingleObject(lThread, 10000) = 0)
If Not lSuccess Then
Call GetExitCodeThread(lThread, lExitCode)
Call ExitThread(lExitCode)
bAns = False
FreeLibraryRegister lLib
Exit Function
Else
bAns = True
End If
CloseHandle lThread
FreeLibraryRegister lLib
Else
FreeLibraryRegister lLib
End If
End If
RegSvr32 = bAns
End Function
[此贴子已经被作者于2017-3-17 15:01编辑过]