Wednesday, December 17, 2008

[vb6] Register COM components

COM components (COM dlls, including ActiveX control libraries) are normally registered by setup programs or manually by using the RegSvr32 utility. If, for some reason you want to register a component in pure code you can do like this instead: First, declare the exported function DllRegisterServer that all COM dlls and ocx's export. To tailor it to your own dlls change the filename and the alias in the declare statement. The function returns 0 on success. The only disadvantage is that you have to know the name of the file at design-time, because declare statements are hard-coded into your executable - there is no such thing as a dynamic declare statement.
    Private Declare Function DllRegisterServerGRADIENTTITLE Lib _
"GradientTitle.ocx" Alias "DllRegisterServer" () As Long
Call the function like this to make the registration:
    Dim retval As Long
retval = DllRegisterServerGRADIENTTITLE

No comments:

Post a Comment