想问个OCX注册的问题
若说我要使用自制或是使用下载或不是VB内建的OCX时~通常都要注册~那我不能使用程序自动帮我做这件事吗?我尝试写了一些代码~但是好像缺了什么~当我到别的电脑开启工程或执行档时~系统依旧会出现错误?我是先從App.Path下複製一份到系統內再用Shell regsvr32 註冊~
介面
程序代码:
Private Sub Form_Initialize() Dim SystemPath As String, OcxPath As String, a As Long SystemPath = GetSysPath & "\EFMTIcn.ocx" OcxPath = App.Path & "\EFMTIcn.ocx" If IsFileExist(OcxPath) = True Or IsFileExist(SystemPath) = True Then If IsFileExist(OcxPath) = True Then FileCopy OcxPath, SystemPath a = Shell("regsvr32 " & SystemPath & " /s", vbHide) ElseIf IsFileExist(SystemPath) = True Then a = Shell("regsvr32 " & SystemPath & " /s", vbHide) End If End If End Sub
模块
程序代码:
Public Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpbuffer As String, ByVal nSize As Long) As Long Const MAX_PATH = 260 Public Function IsFileExist(strFileName As String) As Boolean Dim varFSO As Variant Set varFSO = CreateObject("Scripting.FileSystemObject") IsFileExist = varFSO.FileExists(strFileName) Set varFSO = Nothing End Function Public Function GetSysPath() As String Dim Buffer As String Buffer = Space(MAX_PATH) If GetSystemDirectory(Buffer, Len(Buffer)) <> 0 Then GetSysPath = Mid(Trim(Buffer), 1, Len(Trim(Buffer)) - 1) End If End Function
不知道我是缺了哪个步骤?