我想写一段程序用以注册一个控件!
请问用API怎么写,最好有范例!谢谢

解决方案 »

  1.   

    Option ExplicitPrivate Sub Command1_Click()
        CommonDialog1.ShowOpen
        If Len(CommonDialog1.FileName) > 0 Then
            Shell "regsvr32.exe " & CommonDialog1.FileName
        End If
    End SubPrivate Sub Command2_Click()
        CommonDialog1.ShowOpen
        If Len(CommonDialog1.FileName) > 0 Then
            Shell "regsvr32.exe /u " & CommonDialog1.FileName
        End If
    End SubPrivate Sub Form_Load()
        Command1.Caption = "&Register"
        Command2.Caption = "&Unregister"
        CommonDialog1.CancelError = False
        CommonDialog1.Filter = "*.ocx *.dll|*.ocx;*.dll"
    End Sub
      

  2.   

    在程序中注册和注销 OCX 控件 声明(在本例子里使用的是 ComCtl32.OCX,如果是其他,使用相应的名称): 
    Declare Function RegComCtl32 Lib "ComCtl32.OCX" _ 
    Alias "DllRegisterServer" () As Long 
    Declare Function UnRegComCtl32 Lib "ComCtl32.OCX" _ 
    Alias "DllUnregisterServer" () As Long 
    Const ERROR_SUCCESS = &H0 使用: If RegComCtl32 = ERROR_SUCCESS Then 
    MsgBox "Registration Successful" 
    Else 
    MsgBox "Registration Unsuccessful" 
    End If If UnRegComCtl32 = ERROR_SUCCESS Then 
    MsgBox "UnRegistration Successful" 
    Else 
    MsgBox "UnRegistration Unsuccessful" 
    End If 
      

  3.   

    两种方法分析,
    一:控制台方法,如:leolan(史留香) 
    该方法简单好用,只是结果不大好控制(可以通过保存控制台结果来实现,需要文件操作)
    二:API方法,如: sakurako(最爱API) 
    该方法可以自己控制结果,但不是很灵活,并且控件要放当前目录
    当然,如果你只是固定的某个控件注册,这也是没问题的
      

  4.   

    谢谢大家的支持!sakurako(最爱API)  这个什么
    Declare Function RegComCtl32 Lib "ComCtl32.OCX" _ 
    Alias "DllRegisterServer" () As Long 
    Declare Function UnRegComCtl32 Lib "ComCtl32.OCX" _ 
    Alias "DllUnregisterServer" () As Long 
    直接贴上去就可以了吗?
    还要什么需求吗?怎么不行啊。因为本人没用过API。
    leolan(史留香) 
    你方法我知道但是老板不让用这个好象,有没有注册上不知道,有这么一回事吗?freedomjim(老头)
    谢谢你的总结。
      

  5.   

    哎,因为要自动把那个消息框点掉,所以就不知道有没有成功,所以才用API的
      

  6.   

    Declare Function RegComCtl32 Lib "ComCtl32.OCX" _ 
                        ********      ********
    Alias "DllRegisterServer" () As Long 
    Declare Function UnRegComCtl32 Lib "ComCtl32.OCX" _ 
                          ********      ********
    Alias "DllUnregisterServer" () As Long 对应*号为控件文件的名称!改成你自己想要注册的控件名称!