我现在程序是用这种方法,注册的控件。
'sp是系统目录
'fn是控件文件名
Call Shell(SP & "Regsvr32.exe " & SP & FN)还有哪些好的方法?参考一下

解决方案 »

  1.   

    在运行里写regsvr32.exe 路径\文件名取消是 /u
      

  2.   

    注册后需要在VB中的“工程”中的“部件”中添加上你的OCX控件!
      

  3.   

    rundll32 控件文件名 DllRegisterServer
    rundll32 控件文件名 DllUnRegisterServer
      

  4.   

    用Shell语句来执行:
    Private Declare Function ShellExecute _
        Lib "shell32.dll" _
        Alias "ShellExecuteA" ( _
        ByVal hwnd As Long, _
        ByVal lpOperation As String, _
        ByVal lpFile As String, _
        ByVal lpParameters As String, _
        ByVal lpDirectory As String, _
        ByVal nShowCmd As Long) As Long]Call Shell("Regsvr32 *.OCX")
      

  5.   

    在VB中的“工程”中的“部件”中添加上你的OCX控件!
      

  6.   

    在dos下执行regsvr32 *.cox 就可以了。
      

  7.   

    我做了个注册DLL,和OCX的函数,给大家参考参考啦.----------------------------------------------
    Option Explicit
    '作者:黄炎荣
    '2003-9-29
    'Emai:[email protected]
    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 GetExitCodeThread Lib "kernel32" (ByVal hThread As Long, _
        lpExitCode As Long) As Long
    Private Declare Sub ExitThread Lib "kernel32" (ByVal dwExitCode 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'注册Dll
    Public Function RegDll(ByVal inFileSpec As String) As Boolean
        'On Error Resume Next
        Dim lLib As Long                 ' Store handle of the control library
        Dim lpDLLEntryPoint As Long      ' Store the address of function called
        Dim lpThreadID As Long           ' Pointer that receives the thread identifier
        Dim lpExitCode As Long           ' Exit code of GetExitCodeThread
        Dim mThread
        Dim mresult
        lLib = LoadLibrary(inFileSpec)
        If lLib = 0 Then '加载DLL失败
            MsgBox "Failure loading control DLL"
            RegDll = False
            Exit Function
        End If
        lpDLLEntryPoint = GetProcAddress(lLib, "DllRegisterServer") '加载注册函数
        
        If lpDLLEntryPoint = vbNull Or lpDLLEntryPoint = 0 Then '加载注册函数失败
            FreeLibrary lLib
            RegDll = False
            Exit Function
        End If
        mThread = CreateThread(ByVal 0, 0, ByVal lpDLLEntryPoint, ByVal 0, 0, lpThreadID) '运行注册程序
        If mThread = 0 Then '运行注册程序失败
            FreeLibrary lLib
            RegDll = False
            Exit Function
        End If
        
        mresult = WaitForSingleObject(mThread, 10000)
        If mresult <> 0 Then
            FreeLibrary lLib
            lpExitCode = GetExitCodeThread(mThread, lpExitCode)
            ExitThread lpExitCode
            RegDll = False
            Exit Function
        End If
        
        CloseHandle mThread
        FreeLibrary lLib    RegDll = True
        Exit FunctionEnd Function
    '反注册Dll
    Public Function UnRegDll(ByVal inFileSpec As String) As Boolean
        'On Error Resume Next
        Dim lLib As Long                 ' Store handle of the control library
        Dim lpDLLEntryPoint As Long      ' Store the address of function called
        Dim lpThreadID As Long           ' Pointer that receives the thread identifier
        Dim lpExitCode As Long           ' Exit code of GetExitCodeThread
        Dim mThread
        Dim mresult
        lLib = LoadLibrary(inFileSpec)
        If lLib = 0 Then '加载DLL失败
            MsgBox "Failure loading control DLL"
            UnRegDll = False
            Exit Function
        End If
        lpDLLEntryPoint = GetProcAddress(lLib, "DllUnregisterServer") '加载反注册函数
        
        If lpDLLEntryPoint = vbNull Or lpDLLEntryPoint = 0 Then '加载注册函数失败
            FreeLibrary lLib
            UnRegDll = False
            Exit Function
        End If
        mThread = CreateThread(ByVal 0, 0, ByVal lpDLLEntryPoint, ByVal 0, 0, lpThreadID) '运行注册程序
        If mThread = 0 Then '运行注册程序失败
            FreeLibrary lLib
            UnRegDll = False
            Exit Function
        End If
        
        mresult = WaitForSingleObject(mThread, 10000)
        If mresult <> 0 Then
            FreeLibrary lLib
            lpExitCode = GetExitCodeThread(mThread, lpExitCode)
            ExitThread lpExitCode
            UnRegDll = False
            Exit Function
        End If
        
        CloseHandle mThread
        FreeLibrary lLib    UnRegDll = True
        Exit FunctionEnd Function