locked
COM object using C# RRS feed

  • Question

  • Is it possible to create COM object using C#?
    Monday, October 1, 2018 9:16 PM

Answers

  • Hello,

    Just tick a checkbox Com Visible in project configuration.


    Sincerely, Highly skilled coding monkey.

    • Proposed as answer by cheong00Editor Wednesday, October 3, 2018 1:21 AM
    • Marked as answer by cheong00Editor Monday, October 8, 2018 2:21 PM
    Tuesday, October 2, 2018 6:39 AM

All replies

  • Yes.

    Just call Type.GetTypeFromProgID() to get the Type, and then call Activator.CreateInstance() with the type to get the COM object.


    If you're writing ASP.NET pages, you can also use Server.CreateObject() as you would in ASP pages.
    Tuesday, October 2, 2018 1:25 AM
    Answerer
  • Hi Jeff0803,

    Thank you for posting here.

    For your question, if you want to know how to create a COM object using C#, you could refer to the links below. It shows tutorial and examples.

    https://www.codeproject.com/Articles/7859/Building-COM-Objects-in-C

    https://msdn.microsoft.com/en-us/ie/aa645736(v=vs.94)

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 2, 2018 3:14 AM
  • Hello,

    Just tick a checkbox Com Visible in project configuration.


    Sincerely, Highly skilled coding monkey.

    • Proposed as answer by cheong00Editor Wednesday, October 3, 2018 1:21 AM
    • Marked as answer by cheong00Editor Monday, October 8, 2018 2:21 PM
    Tuesday, October 2, 2018 6:39 AM
  • That's not enough. You still need to tell COM registration what are your interface that you want to declare, and what are the CLSID you want the interfaces be assigned with, optionally what is the class providing implementation if someone want to instantiate it.
    Tuesday, October 2, 2018 6:55 AM
    Answerer
  • It's COM - you need just IUncnown reference.

    Sincerely, Highly skilled coding monkey.

    Tuesday, October 2, 2018 8:07 AM
  • Now tell me, how would you tell COM infrastructure what classes in your code implements IUnknown without necessary attribute annotations?

    Tuesday, October 2, 2018 8:55 AM
    Answerer
  • OP:

    Are you talking about using an existing (3rd party) COM object within your C# code?

    Or are you talking about writing your own COM object in C#?

    Tuesday, October 2, 2018 9:16 AM
  • Again - it's - COM - you need only IUnknown implementation - the rest you will be able to get through IUnknown. COM are designed this way.

    Sincerely, Highly skilled coding monkey.

    Tuesday, October 2, 2018 9:40 AM
  • Have you ever try to create such COM visible project yourself and instantiate an object in your another application without "Add Reference"? Or try to create your COM visible object inside Word/Excel with "Add Reference" there?

    Note that when you use "Add Reference" for a .NET DLL to a .NET application, by default it uses .NET shared object and it has nothing to do with COM. (i.e.: You can use it even if you don't mark your project as "COM visible")



    Tuesday, October 2, 2018 10:03 AM
    Answerer
  • Yes, I did. It was part of extension for Visual Studio 2005.

    And - yes, it's required a registration in registry, as any other COM object, but, if I remember correctly, Studio do such registration on the Build for extensions.


    Sincerely, Highly skilled coding monkey.

    Tuesday, October 2, 2018 10:20 AM
  • Okay. I'm home now and built a little test project to verify it.

    You're correct (Although you also need to check the "Register for COM inteop" in "Build" settings for that auto-register effect). I'll take back my criticism to your answer.

    Tuesday, October 2, 2018 12:06 PM
    Answerer
  • I'm talking about making COM with C#
    Wednesday, October 3, 2018 1:13 AM
  • In that case I think the reply of Andrey Belyakov will solve your problem.
    Wednesday, October 3, 2018 1:21 AM
    Answerer
  • Hello Jeff0803,

    I hope the following can also be helpful to you :

    Creating a COM Server Using C#

    - Bio.


    Please visit my blog : http://limbioliong.wordpress.com/

    Wednesday, October 3, 2018 5:13 AM