Exposing .NET Class as a COM Class
Hello,
I am having problems with exposing a single C# class as a COM Class.
I have a project which compiles to an .exe. I have a C# class which has an interface. I wish to expose this class and only this class as a COM class.
Can you help with an example? Or some steps on how to do this, without creating another seperate project.
I can create a type library and a DLL and I can register these. I can create a class wrapper in VS 6.0 but calling createdispatch fails with not registered. Then I read something about stong names but this gives another problem. Shouldn't it be easier than this!!!!?
You should mark any classes that you do not want exposed to COM with the ComVisible(false) attribute.
Here is an example of a class that will be exposed to COM:
public interface IFoo
{
int Add(int x, int y);
}
[ClassInterface(ClassInterfaceType.None)]
public class Foo : IFoo
{
public in Add(int x, int y)
{
return x+y;
}
}
Make sure that you run regasm.exe on the managed dll...this registers it and allows COM components to create instances of the com visible classes in the managed dll ('regasm /tlb Managed.dll').
Yes, the procedure is the same for an exe.
DarrenStones, does the regasm step give any errors/warnings when you do it outside of VS? If regsvr32 is failing then you might be missing some dependencies...you'll have to debug and figure out why regsvr32 is failing.