I created a 32-bit COM in-process COM server in C++ and registered it. The only functions it exports are those used for COM registration. The registration did not include the entries to APPID and CLSID that I described in my earlier post.
As expected, a 64-bit .Net 6.0 C# console application threw a class not registered exception.
Sample console application -
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using System;
using TestServerLib;
namespace CSNet6Client
{
internal class Program
{
static void Main(string[] args)
{
Guid clsid = new Guid("ec20d466-7a4e-467b-b86a-71de9287d82f");
Guid iid = new Guid("e171eac0-d8c1-4800-a8eb-e47329976806");
try
{
Type t = Type.GetTypeFromCLSID(clsid);
ITestObj server = (ITestObj)Activator.CreateInstance(t);
int plusresult = server.Add(10, 10);
Console.WriteLine($"10 + 10 = {plusresult}");
int minusresult = server.Subtract(100, 53);
Console.WriteLine($"100 - 53 = {minusresult}");
string s = server.Name;
Console.WriteLine($"Name is {s}");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
Before adding registry entries for use of DllSurrogate -
Then I edited the registry to add the necessary information so that the 32-bit COM server would run in the system surrogate process (dllhost.exe).
Results of running the 64-bit .Net 6.0 application using DllSurrogate to host 32-bit COM server- by the way, I fixed a typo in the code that printed the subtraction but didn't bother to rerun the code and post an updated image.
No changes were made to the C# code. The magic was in using the DllSurrogate.