How can I run a 32-bit COM DLL from a 64-bit application?

James Allen 20 Reputation points
2025-12-09T17:09:23.65+00:00

I'm updating a WPF application that's written in C# and currently uses .NET Framework 4.6.1, although I hope to upgrade to a more modern version of .NET as part of the update. My development environment is Visual Studio 2023.

The application uses a 32-bit COM dll (referred to as "DataTest" in the code below). This has been registered using regsvr32, and appears on the list of available COM objects. When added to the "References" section of my project, a DLL named "Interop.DataTest.dll" is created in my \obj directory as expected.

The DLL exposes a single object, "CDataTest", which has various properties and methods. I use the following (very simple) code to instantiate it:

using System;
using DataTest;
namespace MyNameSpace.DataTest
{
    /// <summary>
    /// Wrapper for DataTest CDataTest object
    /// </summary>
    public class DataTest
    {
        private readonly CDataTest _dataTest;
        public DataTest()
        {
            _dataTest = new CDataTest();
        }
    }
}

This works properly if I build my application in "x86" or "Any CPU" mode. However, I have to introduce support for a new driver which will only work in 64-bit mode. If I change my application to build in "x64" mode, I get the following exception when _dataTest is instantiated:

System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {[GUID]} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

[GUID] above is the GUID of the CDataTest class.

Following the advice in https://dori-uw-1.kuma-moon.com/en-us/answers/questions/1855509/how-to-use-32-bit-com-dll-in-a-64-bit-wpf-net-core, I've added the following keys to my registry:

HKLM\Software\Classes\CLSID\{GUID}
HKLM\Software\Classes\AppID\{GUID}

The first key contains only a REG_SZ value "AppID" which is set to the GUID. The second contains only an empty REG_SZ value "DllSurrogate". This has not fixed the issue - I'm still getting the exception when _dataTest is instantiated. Any further help would be most appreciated.

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

1 answer

Sort by: Most helpful
  1. Adiba Khan 1,520 Reputation points Microsoft External Staff
    2025-12-12T07:17:36.5033333+00:00

    Thanks for reaching out based on the details you shared the issue occurs because a 64 bit dot net process cannot directly load a 32 bit COM DLL. This limitation is by design on windows- 32 bit COM components require a 32 bit host process.

    Root cause

    • Your COM DLL is registered using regsvr32.exe (32-bit) -> it registers under HKCR\WOW6432Node.
    • Your application is running as 64 bit so it looks for the COM class under the 64 bit registry hive, where it does not exist
    • therefore, the class shows as not registered

    This is why the application works when compiled as x86, but not AnyCPU/ x64.

    Workarounds

    1. Run your WPF application as 32 bit(recommended and easiest) since the COM DLL is 32 bit compile your application as: project-> properties-> build-> platform target-> x86 this forces the application to run in 32 bit mode and allows the COM DLL to load normally. This is the officially supported method.
    2. Use a 32 bit “COM proxy host” end call it from your 64 bit application windows does not support in process Cross-bit COM loading. However, you can place the 32 bit COM component in a separate 32 bit EXE host, and your 64 bit process can communicate with that EXE using:
      1. WCF
      2. Named Pipe
      3. Out-of-proc COM
      4. gRPC/REST
      5. .NET remoting (legacy)
      this works because 32 bit and 64 bit processes can talk to each other but cannot load each other’s DL.
    3. If the vendor supports it obtain a 64 bit version of the**  **COM DLL if available, replacing the DLL with a native x64 COM library resolves the issue completely

    what does not work

    adding registry keys under:

    HKLM\Software\Classes\CLSID\{GUID}
    HKLM\Software\Classes\AppID\{GUID}
    

    will not fix the issue

    the problem is not registration the problem is bitness mismatch, and windows will not load a 32 bit COM DLL inside a 64 bit process.

    Please let us know if you require any further assistance we’re happy to help. If you found this information useful, kindly mark this as "Accept Answer".

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.