dotnet to com

F

Filip Fransen

Hi,

I have a to create a com object from a dotnet class. Now I have the
following questions :
- with Queryinterface you can get all the interfaces from a com app. How can
I expose my dotnet classes with Queryinterface.
- I can convert a dotnet class with Marshal.GetIUnknowFromObject. Is it
possible to override the queryinterface method in the dotnet class.

Thx

Filip
 
N

Nicholas Paldino [.NET/C# MVP]

Filip,

Basically, you want to know how you can have multiple interfaces served
up from your COM object implementation in .NET.

When creating the class in .NET which you want to be exposed to COM, you
want to attach the following attribute to your class:

[ClassInterface(ClassInterfaceType.None)]
[Guid(...)]
public class MyClass
{ ... }

This will cause your class to not publish an interface based on the
members of your class, but rather, based on any interface implementations
that it implements.

Then, you want to create your interfaces, like so:

[Guid(...)]
public interface IDoSomething
{ ... }

With all the marshalling goo applied. Then, you just implement the
interface on your class. The reason it's important to place the Guid
attribute on the class is so that you have control over the class id of your
type. The reason it is important on the interface is so you have control
over the interface id which is needed when you make your calls to
QueryInterface.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top