Programmatically register an ActiveX control or DLL

Programmatically register an ActiveX control or DLL

All ActiveX DLL or OCX export two functions: DllRegisterServer and DllUnregisterServer. They are used to register and unregister the ActiveX in the Windows registry, and are usually invoked from regsvr32.exe at registration time.

However, you can register and unregister these files programmatically whenever you want to, provided that you know the name of the DLL or OCX at compile time. All you have to do is prepare two aliased functions, as in the following example, that shows how to register and unregister the COMCTL32.OCX file:

'function to call to register the ActiveXPrivate Declare Function RegComCtl32 Lib "COMCTL32.OCX" Alias _    "DllRegisterServer" () As Long' function to call to unregister the ActiveXPrivate Declare Function UnRegComCtl32 Lib "COMCTL32.OCX" Alias _    "DllUnregisterServer" () As LongConst ERROR_SUCCESS = &H0

Note that the two functions work only if the DLL is in the system path or in the current directory. Therefore, if you want to register a DLL located elsewhere on your hard disk, you must use ChDrive and ChDir commands to make that directory the current one. For example, say that the you have a Test.DLL file in the C:MyApp directory. Here’s the code you need to register it:

Private Declare Function RegisterTestDLL Lib "Test.Dll" Alias _    "DllRegisterServer" () As LongDim retCode As LongOn Error Resume Next' move to the DLL's directoryChDrive "C:"ChDir "C:MyApp"' register the DLLretCode = RegisterTestDLL()If Err <> 0 Then    ' probably the DLL isn't there    MsgBox "Unable to find the Test.Dll file"ElseIf retCode <> ERROR_SUCCESS Then    ' the registration run and failed     MsgBox "Registration failed"End If

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes