You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I am trying to play with comwrappers to understand how they work and how they are to be implemented. Less interested in implementation internals, but... using a source generator is explicitly out of this exercise and I am not using net8 yet.
I succeeded in implementing a com host with it's own IClassFactory. I planned to practice adding a free threaded marshaller to managed object wrappers I create, and that requires aggregation. However, I don't understand how aggregation works in com wrappers. I came across this #44446 and I don't really understand the api shape.
My understanding of aggregation at com level is:
After getting a managed object wrapper I need to create the aggregatable object, for example a free threading marshaler using CoCreateFreeThreadedMarshaler, which is my inner object, and I get it's IUnknown interface pointer. I can of course have something else to aggregate or make my own aggregables.
Then, i somehow need to associate it with the MOW. How? I see the GetOrRegisterObjectForComInstance with the inner parameter, but I don't understand why does it work that way? if inner is my inner object, what's the external com object parameter going to be set to, and why? example in the issue suggests it's going to be the non IUnknown interface of inner, but for me it doesn't make sense, because when would I even have that pointer and need to retrieve back the instance? Normally when I get such a pointer it means I want to call it's methods which will not ever call into dotnet... If externalComObject would be my MOW, then it also doesn't make sense because it seems like that argument is useless and api should just allow setting the inner. What am I missing in the scenario?
What happens if I need to do aggregate multiple things? Imagine a free threaded marshaller and something else. Or this is not really supported by aggregation model? I think aggregation model doesn't care.
And then I need to implement my own QueryInterface. do i use ICustomQueryInterface or just wrap runtime's IUnknown implementation? both should work imo. In both cases it seems like I have to hold the inner pointer in the object and call QueryInterface on it, so still unsure why registration works that way.
How does the Unwrap flag relate to the scenario? It's added along with aggregation support, but I don't see how that even relates...
What is the lifecycle of managed object wrapper? is it deallocated on last release or on gc of the managed object? For example if I pass an aggregate to COM then release it but still hold managed object, will the inner be released? or maybe it won't be released and I am allowed to request the MOW again, which will work until both MOW and managed object become unreferenced?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I am trying to play with comwrappers to understand how they work and how they are to be implemented. Less interested in implementation internals, but... using a source generator is explicitly out of this exercise and I am not using net8 yet.
I succeeded in implementing a com host with it's own IClassFactory. I planned to practice adding a free threaded marshaller to managed object wrappers I create, and that requires aggregation. However, I don't understand how aggregation works in com wrappers. I came across this #44446 and I don't really understand the api shape.
My understanding of aggregation at com level is:
Beta Was this translation helpful? Give feedback.
All reactions