June 30th, 2012, 03:54 PM
Exposing a creatable class to COM as a pure interface
When exposing .NET classes to COM, MSDN recommends to explicitly define any interfaces. In the DLL project I'm currently working on, I did just that and it worked. I made the interface COM-visible and set the class' class interface type to none (COM-invisibility is inherited from the assembly). The class has no default c'tor, just one that takes parameters, so it's not creatable via COM, but I'm fine with that: I simply need a factory to deploy the objects. So far, so good.
The factory class, of course, needs to be creatable via COM (though it's stateless). Setting that up as described above makes the factory end up effectively being non-creatable from the COM perspective, though this one does have an (implicitly defined) default c'tor. I also tried to explicitly define a no-op default c'tor but that didn't change anything. The only way I could get it to work by now is using the implicitly generated class interface instead of the explicitly defined one, but besides the fact that I simply don't like it, it also gets me the "bonus" of the four exposed methods inherited from Object.
It works like it is now, but isn't there another way of doing that? I haven't seen anything enlightening about that on MSDN, though of course the situation should be quite common: One would always need at least one creatable class to be exposed, of course, wouldn't they? Sure, interfaces as such are non-creatable by nature. And I didn't find any nifty way of explicitly specifying a c'tor in the interface or a framework-defined interface I could inherit that implies default-cunstructability.
Any thoughts or hints?
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!