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

James Allen 0 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://v4.hkg1.meaqua.org/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.
0 comments No comments
{count} votes

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.