-
I'm using .NET 8 (and AOT), my csproj looks this this:
and I also have
Let's say I have a native COM object that supports 2 interfaces: Let's say I can get an instance of this COM object using for example a function, like
(I've tried If I do this:
Then This, on the other end, works fine:
Is this expected? What am I missing? Should I always start with an IntPtr? It looks weird. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
This seems like a very COM-ish way to do something in .NET. I have my library declaration defined the same way you have, and I simply do this:
It'd be helpful to see how the interface is declared as well. Are you using [GeneratedComInterface] ?
|
Beta Was this translation helpful? Give feedback.
-
Ok , I finally got it. Calling this:
Works fine but is not what I want. I find the doc here https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.comwrappers.getorcreatecominterfaceforobject a bit ambiguous, it says:
So what is does is "create" a Managed Object Wrapper (used to be called CCW) that here doesn't implement interfaces of course, but since the COM object is already a native object we just want it's original (or wrapped) pointer. And this is available using the ComWrappers.TryGetComInstance(Object, IntPtr) Method:
So in my code:
IMHO, doc is ambiguous and unclear here and the overall API shape & naming (ComInstance vs ComInterface, etc.) is also a bit strange. This all misses examples. |
Beta Was this translation helpful? Give feedback.
Ok , I finally got it.
Calling this:
Works fine but is not what I want. I find the doc here https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.comwrappers.getorcreatecominterfaceforobject a bit ambiguous, it says:
So what is does is "create" a Managed Object Wrapper (used to be called CCW) that here doesn't implement interfaces of course, but since the COM object is already a native object we just want it's original (or wrapped) pointer.
And this is available using the ComWrappers.…