kant2002 / CoMallocNativeAot

5 stars 0 forks source link

Does NativeAOT support COM and COM Server #1

Open frenchfish opened 9 months ago

frenchfish commented 9 months ago

Hello do you know how to make Comobject in Native AOT (which will be used in native )

kant2002 commented 9 months ago

Hi. Currently NativeAOT lacking of support for Com servers. The link https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.comwrappers.getorcreateobjectforcominstance?view=net-8.0 which you gave to me in email, does not the help with createion of COM server.

If you brave enough, you can create DLL where you export nescessary functions 'DllGetClassObject' at minimum and implement IClassFactory you can do the trick.

You can see how it was done in managed profiler.

https://github.com/kevingosse/ManagedDotnetProfiler/blob/master/ManagedDotnetProfiler/DllMain.cs

https://github.com/kevingosse/ManagedDotnetProfiler/blob/master/ProfilerLib/ClassFactory.cs

Be careful, since all marshalling between COM datatypes and .NET datatypes you have to do yourself.

frenchfish commented 9 months ago

https://github.com/kevingosse/ManagedDotnetProfiler/blob/master/ManagedDotnetProfiler/DllMain.cs

https://github.com/kevingosse/ManagedDotnetProfiler/blob/master/ProfilerLib/ClassFactory.cs

Be careful, since all marshalling between COM datatypes and .NET datatypes you have to do yourself. Thanks. Great tip