How to Register and Unregister a DLL or ActiveX Controls Using Regsvr32.exe

How to Register and Unregister a DLL or ActiveX controls using Regsvr32.exe

  1. Regsvr32.exe is a program that you can use to register and unregister dynamic-link libraries (DLLs) and ActiveX controls (formerly called OLE Custom Controls) in the registry.
  2. Regsvr32.exe is installed in the System folder. On a 64-bit version of a Windows operating system, there are two versions of the Regsv32.exe file:
    - The 64-bit version is %systemroot%\System32\regsvr32.exe.
    Path: C:\Windows\System32\regsvr32.exe
    - The 32-bit version is %systemroot%\SysWoW64\regsvr32.exe.
    Path: C:\Windows\SysWOW64\regsvr32.exe
  3. Regsvr32 is the command-line tool that registers DLL files as command components in the registry.
  4. Regsvr32 is used for registering a COM based DLL. Regsvr32 generates, registers, and installs a type library into a specified COM+ 1.0 application.
  5. To be used with regsvr32, a DLL must export the functions DllRegisterServer and DllUnregisterServer.
  6. Regsvr32 will load the library and try to call the DllRegisterServer() from that library. It doesn't care what DllRegisterServer() actually does – it just calls that function and checks the returned value.
  7. You use it to register COM servers in unmanaged DLLs.
  8. It can't generate a .tlb file.
  9. Most often, RegSvr32.exe fails because the LoadLibrary, DllRegisterServer, or DllUnregisterServer function fails.
  10. LoadLibrary can fail because:
    - If the DLL is not in the specified path, or if the specified path is incorrect.
    - If one of the dependencies of the DLL that you are trying to load is not met; in other words, if a dependent DLL is not present or is not in the specified path.
  11. You can use the Depends.exe tool to check whether or not all of the dependencies of your DLL are met.
  12. Your DLL must implement DllRegisterServer and DllUnregisterServer, that contain the logic that is necessary to add or delete the required registry entries for the COM component. RegSvr32.exe finds the entry point to these functions, and calls them appropriately.
  13. If you use the Microsoft Active Template Library (ATL) Wizard to create the COM DLL, the Wizard generates the necessary code for DllRegisterServer and DllUnregisterServer.

Register a DLL using regsvr32.exe

  1. RegSvr32.exe has the following command-line options:

    Regsvr32 [/u] [/n] [/i[:cmdline]] dllname

    - /u - Unregister server
    - /i - Call DllInstall passing it an optional [cmdline]; when used with /u calls dll uninstall
    - /n - Do not call DllRegisterServer; this option must be used with /i
    - /s - Silent; display no message boxes (added with Windows XP and Windows Vista)
     
  2. For example, to manually register the Sample.ocx ActiveX control, you would type the following at the command prompt:

    C:\Regsvr32.exe Sample.ocx

    NOTE: This command line assumes that Regsvr32.exe and Sample.ocx are both in the root folder of drive C.

Unregister a DLL using regsvr32.exe

  1. For example, to manually unregister the Sample.ocx ActiveX control, you would type the following at the command prompt:

    C:\Regsvr32.exe /u Sample.ocx

    NOTE: This command line assumes that Regsvr32.exe and Sample.ocx are both in the root folder of drive C.

Common errors while registering a DLL using regsvr32.exe

  1. The command-flag "%1" is not valid. Please review the command usage and try again.

    Cause: The user entered an invalid combination of command line switches or arguments when invoking the regsvr32.exe application.
     
  2. This command is only valid if a Microsoft Visual Studio OLE Custom Control project is opened.

    Cause: Microsoft Visual Studio invoked or ran the regsvr32.exe application but there were not modules included in the command line arguments.
     
  3. To register a module, you must provide a binary name.

    Cause: Regsvr32.exe was invoked or called with no modules to register located in the command line arguments.
     
  4. The command OleInitialize failed to run. Your computer might be low on memory. Close any open programs and then try again.

    Cause: The regsvr32.exe tool has to initialize the Microsoft COM library before calling the required COM library functions. It also has to unitialize the library when it shut down. Typically this results when either action has failed. If no cause can be determined then this can sometimes be solved by restarting the computer system.
     
  5. The module "%1" failed to load.\n\n Make sure the binary is stored at the specified path or debug it to check for problems with the binary or dependent .DLL files.\n\n%2.

    Cause: Windows had issues with loading the module identified in the command line. The specific error text will be provided as part of the message.
     
  6. The module "%1" was loaded but the entry-point %2 was not found. \n\n Make sure that "%1" is a valid DLL or OCX file and then try again

    Cause: The regsvr32.exe application was not able to locate the entry point to the module identified in the command line. This commonly results from improper entrypoint exportation from the module or if the file is not truly a DLL or .OCX file.
     
  7. The module "%1" was loaded but the call to %2 failed with error code %3. \n\n For more information about this problem, search online using the error code as a search term.

    Cause: When regsvr32.exe invoked the entrypoint in the DLL module an error was thrown. The specific error code will be included with the displayed message.
     
  8. The module "%1" may not compatible with the version of Windows that you're running. Check if the module is compatible with an x86 (32-bit) or x64 (64-bit) version of regsvr32.exe.

    Cause: Commonly occurs if the 32 bit version of regsvr32.exe is run with a 64 bit version of the DLL.