1

Can a .NET component be used from a COM component?

1
  • Your question is not so clear. Commented Jul 1, 2009 at 6:50

3 Answers 3

4

Read this

Calling a .NET Component from a COM Component

Sign up to request clarification or add additional context in comments.

1 Comment

While this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
2

Yes, it's possible.

As thoroughly explained in this CodeProject article, there are two ways to do it:

  1. Early binding, which involves using a tool (Type library Importer, or tlbimp.exe) to create a binary file (a .NET assembly) which contains metadata necessary for the CLR to instantiate the Runtime Callable Wrapper for the COM object. This provides all the strong typing benefits, because you can reference the generated assembly and use these classes like any other .NET classes in your code.

  2. Late binding, which uses the Type.InvokeMember method to invoke methods of a COM object by their name, during runtime. Since this approach is weakly typed, it's more error prone than early binding, but it also allows greater flexibility.

1 Comment

@BilltheLizard: oh, crap, the question was about consuming .NET from COM, not vice versa. Have to run now, I'll fix it later.
1

Yes, you can do it (like mentioned in the other answers).

It basically boils down to exposing your .NET component as a COM component (this can be done by signing your assembly and just flipping a switch [Make assembly COM-Visible] in the Assembly Information Dialog Box, but good practice demands to implement an interface, and expose only the interface using the ComVisibleAttribute).

This way, your COM component can talk to the .NET component as if it is also a COM component.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.