[求助]请教如何用VB代码注册控件?
请教如何用VB代码注册控件? 我没有直接试过,但是你确实可以试试这个思路:VB编程动态注册ActiveX控件<BR> 在使用VB和其它一些Win9X下的编程软件,就要同ActiveX控件打交道,注册<BR>和反注册控件是一件令人很头疼的事情。有时从网上下载了一个控件,但是在使用<BR>时VB总是提示控件没有注册。又或者想删除一个控件却无法从注册中抹去。<BR> 实际上,每一个ActiveX控件都有两个输出函数:DllRegisterServer和<BR>DllUnRegisterServer。顾名思义,通过这两个函数就可以注册和反注册控件了,<BR>下面通过程序说明如何通过编程来注册。<BR> 首先在Form中加入两个CommandButton,不要改变它们的属性。然后在Form中<BR>加入如下代码:<BR>Private Declare Function RegComCtl32 Lib "ComCtl32.OCX" _<BR> Alias "DllRegisterServer" () As Long<BR>Private Declare Function UnRegComCtl32 Lib "ComCtl32.OCX" _<BR> Alias "DllUnregisterServer" () As Long<BR>Private Declare Function FormatMessage Lib "kernel32" _<BR> Alias "FormatMessageA" (ByVal dwFlags As Long, _<BR> lpSource As Any, ByVal dwMessageId As Long, _<BR> ByVal dwLanguageId As Long, ByVal lpBuffer _<BR> As String, ByVal nSize As Long, Arguments As _<BR> Long) As Long<BR>Private Declare Function GetLastError Lib "kernel32" () As Long
Const ERROR_SUCCESS = &H0
Private Sub Command1_Click()<BR> Dim astr As String<BR> <BR> '反注册ComCtl32.Ocx<BR> If RegComCtl32 = ERROR_SUCCESS Then<BR> MsgBox "注册成功"<BR> Else<BR> astr = String$(256, 20)<BR> FormatMessage FORMAT_MESSAGE_FROM_SYSTEM Or _<BR> FORMAT_MESSAGE_IGNORE_INSERTS, 0&, GetLastError, _<BR> 0&, astr, Len(astr), ByVal 0<BR> MsgBox astr<BR> End If<BR>End Sub
Private Sub Command2_Click()<BR> Dim astr As String
'反注册ComCtl32.Ocx <BR> If UnRegComCtl32 = ERROR_SUCCESS Then<BR> MsgBox "反注册成功"<BR> Else<BR> astr = String$(256, 20)<BR> FormatMessage FORMAT_MESSAGE_FROM_SYSTEM Or _<BR> FORMAT_MESSAGE_IGNORE_INSERTS, 0&, GetLastError, _<BR> 0&, astr, Len(astr), ByVal 0<BR> MsgBox astr<BR> End If<BR>End Sub<BR> 运行程序,点击Command2反注册ComCtl32.Ocx控件,在VB菜单中选 Project|components<BR>或按Ctrl+T,在控件列表框中可以看到已经没有ComCtl32.Ocx了。再运行程序,点击Command1<BR>重新注册控件。<BR> 以上程序再VB5,WIN95下运行通过。<BR> 谢版主,我试试
页:
[1]