How to Register an ActiveX DLL using regsvr32

The first step is to determine if you need to register the ActiveX DLL compiled for 32-bit or 64-bit.  If your computer is 32-bit, the choice is obviously 32-bit.  Let’s start with it:

How to Register a 32-bit DLL on a 32-bit Windows operating system

  1. Using a text editor, create a .bat file in the same directory as the 32-bit DLL.
  2. Insert this line in the .bat file:
    regsvr32 "%CD%"\myActiveX.dll
  3. Run the .bat “as Administrator”. regsvr32 will be trying to create entries in the Windows registry, so it may need administrative privileges.

    * On Windows 7, open an Administrator command prompt by going to the Start Menu, enter “cmd” in the search box and instead of pressing Enter, press Ctrl+Shift+Enter. Change directories to where the DLL’s and the batch script are located, and run the registration batch file from there.

regsvr32 on 64-bit Windows

If the computer is 64-bit Windows, it’s possible you still may need the 32-bit DLL.  It depends on whether your application runs as a 32-bit process or a 64-bit process.  If using the ActiveX from ASP, check to see if IIS is running in 32-bit mode or 64-bit mode.  If 32-bit, the 32-bit ActiveX needs to be registered.  Likewise, if IIS is running in 64-bit mode, register the 64-bit ActiveX DLL.   For VB6 apps, it will always be 32-bit because VB6 is older and there is no such thing as a 64-bit VB6 app.  This may also apply to older versions of other programming languages such as Delphi, FoxPro, etc.

If you are unsure, there is no harm in downloading and registering both 32-bit and 64-bit DLLs.  64-bit Windows has separate registries for 32-bit and 64-bit, so both may be registered.

How to Register a 32-bit DLL on a 64-bit Windows operating system

  1. Using a text editor, create a .bat file in the same directory as the 32-bit DLL.
  2. Insert this line in the .bat file:
    \windows\syswow64\regsvr32 "%CD%"\my_32_bit_ActiveX.dll

    It is the 32-bit version of regsvr32 that must be used to register the DLL in the 32-bit registry. We use the full path to regsvr32 to make sure we’re running the 32-bit version.

  3. Run the .bat “as Administrator”.

    * On Windows 7, open an Administrator command prompt by going to the Start Menu, enter “cmd” in the search box and instead of pressing Enter, press Ctrl+Shift+Enter. Change directories to where the DLL’s and the batch script are located, and run the registration batch file from there.

How to Register a 64-bit DLL on a 64-bit Windows operating system

  1. Using a text editor, create a .bat file in the same directory as the 64-bit DLL.
  2. Insert this line in the .bat file:
    \windows\system32\regsvr32 "%CD%"\my_64_bit_ActiveX.dll

    It is the 64-bit version of regsvr32 that must be used to register the DLL in the 64-bit registry. We use the full path to regsvr32 to make sure we’re running the 64-bit version.

  3. Run the .bat “as Administrator”.

    * On Windows 7, open an Administrator command prompt by going to the Start Menu, enter “cmd” in the search box and instead of pressing Enter, press Ctrl+Shift+Enter. Change directories to where the DLL’s and the batch script are located, and run the registration batch file from there.

Using regsvr32 to Register a 32-bit ActiveX or 64-bit ActiveX on Windows 64-bit System

A 64-bit Windows system has two separate registries — one for 32-bit processes, and one for 64-bit processes. The reason for this is simple: Let’s say your application instantiates an instance of an ActiveX component by calling CreateObject(“Chilkat.Ssh”). If your application is running in a 32-bit address space, the registry entries for “Chilkat.Ssh” should point to a 32-bit DLL in the filesystem. However, if your application is running in a 64-bit address space, the registry entries should point to a 64-bit DLL. The only possible way to do it is to have separate registries — one for 32-bit and one for 64-bit.

On a Windows 64-bit computer, the regsvr32 program (located in \windows\system32) is a 64-bit program that registers a 64-bit ActiveX DLL using the 64-bit registry. For example:

regsvr32 ChilkatSsh_x64.dll

On Windows x64, regsvr32 expects a 64-bit DLL and updates the 64-bit registry.

To register a 32-bit ActiveX DLL in the 32-bit registry, you’ll need to run the regsvr32 located in \windows\syswow32. For example:

cd \windows\syswow64
regsvr32 c:\ChilkatSsh.dll

It’s important to know whether the program that will be loading the ActiveX is 32-bit or 64-bit. For example, IIS on Windows 64-bit can run as either. If IIS is running in 32-bit mode, any ActiveX’s used in your ASP pages should be 32-bit DLL’s registered in the 32-bit registry. Likewise for 64-bit.

The same conditions apply for other environments, such as SQL Server 2008. Is the database server running as a 32-bit process or 64-bit process? If an ActiveX is used within a stored procedure, make sure the appropriate DLL is registered to the appropriate registry…

Error 0x8002801D when Instantiating Chilkat HTTP ActiveX

This error indicates that there is a
problem with the registry information for the ActiveX DLL. The registry
entry may be missing or contain incorrect information, or the user may
not have permission to read the registry entry.

In ASP, the error message may look like this: 
Server object error ‘ASP 0177 : 8002801d’

In applications, you may see an error message such as this: 
OLE error code 0x8002801d: Library not registered

First try unregistering and re-registering the DLL.  On the computer or server where the ChilkatHttp.dll is located, open a DOS prompt and “cd” to the directory where the DLL is located.  Then unregister by typing:

regsvr32 -u ChilkatHttp.dll

Next, register the ActiveX DLL by typing:

regsvr32 ChilkatHttp.dll

If it fails, then create a .bat file in the same directory as the DLL.  Type the “regsvr32 ChilkatHttp.dll” command into the .bat script.  Right-click on the .bat and select “Run as Administrator”.  This should register the DLL.   Check to see if the problem is resolved in your ASP page or application.

Finally, if the problem remains, it could be a permissions problem. (I have no idea why the permissions
might be different..) In any case, please see the information at this Microsoft
support knowledge-base article. It provides details about changing the
registry entry permissions so that your ASP code has permission to read
the registry entries:

http://support.microsoft.com/kb/274038

A .NET Assembly is *not* an ActiveX. It is not registered via regsvr32.

Question:

I have now tried to register the component manually, but then I get his
message:

"The module c:\...\ChilkatDotNet2.dll was loaded but the entry-point
DllRegisterServer was not found.
Make sure that c:\...\ChilkatDotNet2.dll is a valid DLL or OCX file and try
again."

Answer:

A .NET assembly is not an ActiveX component. It is not registered with regsvr32. If your application is written in C# or VB.NET (i.e. it is a .NET application), then you simply add a reference to the Chilkat assembly (such as ChilkatDotNet2.dll) within your Visual Studio project. If you need to use the ActiveX component from other languages, such as VB6, ASP, FoxPro, Delphi, etc., then download the ActiveX from http://www.chilkatsoft.com/downloads.asp and install. If the ActiveX DLL is already installed and you need it on another computer, you may simply copy the ActiveX DLL and register with regsvr32. Please read this blog post about using ActiveX components on win32 / x64.

Incorrect Format Error when trying to load .NET Assembly

This Chilkat blog post explains the following error:

"Could not load file or assembly 'ChilkatDotNet2, Version=9.0.8.0, Culture=neutral,
PublicKeyToken=eb5fc1fc52ef09bd' or one of its dependencies.
 An attempt was made to load a program with an incorrect format."

When a DLL is loaded, it is mapped into the process’s address space. If the process is running in a 32-bit address space, the DLL must also use a 32-bit address space. (In other words, it should be a DLL compiled for the Win32 platform.) If the process loading the DLL is running in a 64-bit address space, the DLL must match — i.e. it should be a DLL compiled for the x64 platform.

This applies to both .NET assemblies *and* ActiveX DLLs.

64-bit Windows is capable of running applications in both 32-bit mode and 64-bit mode. If your application is running in a 32-bit address space, the DLLs it loads must also be 32-bit. If your application is running in a 64-bit address space, the DLLs it loads must also be 64-bit. Just because your application is running on 64-bit Windows does not mean it requires a 64-bit DLL — the determining factor is the process’s address space.

For example, let’s say you’ve configured IIS to run its worker processes in 32-bit mode. In that case, your ASP or ASP.NET apps would require 32-bit DLLs. If IIS is running in 64-bit mode, then 64-bit DLLs are needed.

Important: The “Incorrect Format” error is only caused by one thing: The address space (32-bit or 64-bit) of the process loading a DLL does not match the DLL’s address space. Quite often developer get stuck on this problem because they don’t know one or both of the following:

  1. Is your application running in a 32-bit address space or 64-bit?  You’ll need to know this.  If running in 32-bit, you can ignore the 64-bit DLL builds altogether because you’ll never need them.  For .NET applications in Visual Studio you may target “win32” instead of “Any CPU” to force your executable to run in a 32-bit address space.  In 99% of all cases, this is not an issue — does your application really need more than 4GB of memory?
  2. You’re not loading the DLL you *think* your loading.  With ActiveX, are the registry entries created by regsvr32 really pointing to the DLL in the filesystem that you’re intending to use?  (For more information: regsvr32 registry entries)  With .NET, is the assembly found by the .NET runtime loaded from the GAC?  Is it found in the directory where you think it should be found?

About the Windows registry and ActiveX:  The following applies only to ActiveX DLLs and not .NET assemblies.  .NET assemblies are not registered with regsvr32 and have no registry entries required for locating the DLL when loading.

A 64-bit Windows system has two separate registries — one for 32-bit processes, and one for 64-bit processes.  The reason for this makes sense if you think about it..   Let’s say your application instantiates an instance of an ActiveX component by calling CreateObject(“Chilkat.Ssh”).   If your application is running in a 32-bit address space, the registry entries for “Chilkat.Ssh” should point to a 32-bit DLL in the filesystem.  However, if your application is running in a 64-bit address space, the registry entries should point to a 64-bit DLL.  How can you do both with one registry?  The answer is to have separate registries — one for 32-bit and one for 64-bit.

Therefore, when you register a DLL with regsvr32 — did you register the 32-bit DLL in the 32-bit registry, or did you register the 64-bit DLL in the 64-bit registry?  You’ll need to get it right.  When you run regsvr32 on an x64 system, you’re running the 64-bit version by default.  (That’s a bit confusing because of the “32” in the regsvr32 name…)  To run the 32-bit regsvr32, do this:

cd \windows\syswow64
regsvr32 c:\filename.dll

(Note the stupidity of it all — the default regsvr32 is 64-bit and resides in the \windows\system32 directory.  Note the “32” in system32 and the “32” in regsvr32 — quite misleading.  However the 32-bit version of regsvr32 is found in the \windows\syswow64 directory.  Note the “64” in the directory name.  That’s also misleading.  Ughhh!)

More information about: regsvr32 or ActiveX object creation errors.

REGSVR32 0x80070005 Error on x64 Windows 7

The download for the Chilkat x64 ActiveX components includes a register.bat batch file for registering each of the Chilkat ActiveX DLLs.  If some or all of these fail with an error code of 0x80070005, it is because of a permissions problem.  Do the following to successfully register the ActiveX DLL’s on the system:

  1. Copy the DLL’s to c:\Windows\System32
  2. Right-click on the “register.bat” file and select “Run as administrator”.
  3. The DLL’s should register.

regsvr32 0x80020009 error and solution

Question:
I am having a problem registering the ChilkatCrypt2.dll and ChilkatMail_v7_9.dll files using regsvr32.
I get the following error message: 0x80020009
I am using Windows Server 2008 R1 and will also need to register on 2008 R2 (have not tried yet).

Solution:
Regsvr32 needed to be run in a command window that was run as an administrator.

Also: Regarding regsvr32 / ActiveX registration problems, see this blog post: regsvr32 problems.

regsvr32 Problems

ActiveX components and controls have been around for many years.  Unfortunately, when regsvr32 fails to register a DLL, the only information provided is an error code.  Usually in the format of a 32-bit hex number, such as 0x80004005 (although not necessarily that particular error code, I simply picked one at random for this blog post).

If you search the Internet, you’ll soon realize that regsvr32 has been a “pain-in-the-butt” for many many years (not just for Chilkat DLL’s, but for all ActiveX DLL’s including Microsoft’s very own).  The biggest problem is that there’s NO information about why it failed, and there are a large number of potential reasons — and the list of reasons and the complexity of operating system security/access/permissions is ever-increasing.

A natural reaction is to assume that the problem must be related to something within the DLL.  In the case of Chilkat ActiveX DLL’s, this is always NOT true.  The Chilkat ActiveX’s are standard self-registering ActiveX components, and the internal code relating to regsvr32 registration is exactly what is generated by Microsoft Visual Studio for ATL/COM projects.  It has been unchanged for approx. 10 years.  Therefore, any problem with regsvr32 is always a result of the environment, usually security, permissions or access restrictions.  For example, does the DLL reside on a UNC path that is not local to the computer and therefore not trusted?  The best way to solve a regsvr32 problem is to Google the error code returned by regsvr32.

I hope that one day Microsoft improves the regsvr32 error message to give us some sort of clue about the cause of a regsvr32 failure…