How to: Write an ActiveX object in C#?

I know ActiveX is kind of stoneage but I have to write one... So. How do you go about writing an ActiveX object (not neccessarily a control) in C# This example http://www.c-sharpcorner.com//Code/2003/March/ActiveXInNet.asp is not a real ActiveX object it doesn't register itself in the registry. This example http://www.devhood.com/messages/message_view-2.aspx thread_id=16569 doesn't work.



Answer this question

How to: Write an ActiveX object in C#?

  • Ravi G

    It is possible to create unmanaged COM applications using C#. I have built many of these for legacy asp applications.


    But is that a real COM application It should be a managed application consumed from ASP (or COM) through COM-.NET interoperability, isnt it It still requires .NET runtime to be installed on the machine, doesnt it If so it is still a managed application.


  • vnapoli

    It is possible to create unmanaged COM applications using C#. I have built many of these for legacy asp applications.

  • Amisur

    That is correct.. You can call it managed or unmanaged (technically managed), although it is still a "real" COM application.

    I usually refer to my C# COM objects as "unmanaged C#". Not because they are, but because I created them primarily to work with unmanaged languages. I have never once used my C# COM objects in a .Net application.


  • emredincer

    Consuming a .NET component from COM is not the same as building an ActiveX component in C#. It is just like saying using COM components in .NET applications is same as building a managed component using COM.

  • Arshad Syed

    That is not building ActiveX component in C#, but consuming an ActiveX component from C# through COM-.NET interoperability. The ActiveX component is still built using a COM aware language like VC++ or VisualBasic 6.

  • zx6r

    I dont think you can build ActiveX controls in C# since ActiveX is based on COM. What you can do is build it in VC++ or VisualBasic 6 and use it from your C# code.
    It would be good if you could give us more context on what you are trying to acheive.


  • Benjamin Wulfe - MS

    > But is that a real COM application
    Yes
    > It should be a managed application consumed from ASP (or COM) through COM-.NET interoperability, isnt it
    Yes
    > It still requires .NET runtime to be installed on the machine, doesnt it
    Yes
    > If so it is still a managed application.
    Yes

    This is just a matter of terminology. The fact that it requires the .NET runtime doesn't make it any less a COM object than, say, a COM object written in VB6 (which needs the VB6 runtime). COM doesn't care about the internal implementation or dependencies of a component.



  • ComputerJy

    > That is not building ActiveX component in C#...
    Yes it is. The link is to the article "Exposing .NET Framework Components to COM", which describes how to build a component using .NET managed code and consume it from an unmanaged component. The .NET component is exposed via a COM-Callable Wrapper (CCW)

    > consuming an ActiveX component from C# through COM-.NET interoperability
    This is also possible of course. In this case .NET clients call unmanaged COM components via a runtime callable wrapper (RCW). There is a different article that describes this: http://msdn.microsoft.com/library/en-us/cpguide/html/cpconexposingcomcomponentstonetframework.asp


  • Xee

    This example shows how to do it: http://www.codeproject.com/cs/miscctrl/exposingdotnetcontrols.asp df=100&forumid=2373&exp=0&select=1359005


  • Sabrecat

    > I dont think you can build ActiveX controls in C# since ActiveX is based on COM.

    Sure you can. A good starting point is http://msdn.microsoft.com/library/default.asp url=/library/en-us/cpguide/html/cpconexposingnetframeworkcomponentstocom.asp


  • How to: Write an ActiveX object in C#?