C# with COM

Started by
2 comments, last by Micko 19 years, 10 months ago
I''m trying to use a COM dll that is an add on to an application that I''m connecting to using C#. Its an add on for AutoCAD and I need to get an instance of it to extract info from the drawing of these custom objects. Here''s how it''s done in vb-

''connect to Acad
Set acadApp = CreateObject("AutoCAD.Application")

''connect to Acad add on
Set Obj = acadApp.GetInterfaceObject("SOMECOMWRAPPER.SomeComApplication")                
If Not Obj Is Nothing Then                        
	MsgBox "Found installed SomeAddOnApp version " & Obj.VersionString            
               
End If  
Any help appreciated.Mick
Advertisement
It's pretty straight forward in C# (and I believe it's the same procedure for VB.NET), though it's not quite as simple as in VB.

1) Run tlbimp on the native binary that has your COM component in it.

2) Declare a COM coclass in your C# source, using the ComImportAttribute.

3) Create the class and run with it. You have to add the managed assembly generated in step 1 as a reference to your C# project.

Here's the tutorial on how to do COM Interop in C#


[edited by - Alias2 on June 2, 2004 2:49:07 AM]
Thanks Alias2, I''ll let you know how I get on after getting my head around that.
Cheers.Mick
If you are using Visual Studio then it''s enough to just add a reference directly to the COM dll. VS will automatically create the managed wrapper and reference it, so you can work with the COM dll just the same as with a normal managed dll.

This topic is closed to new replies.

Advertisement