none
How can we use ActiveX controls created using .NET, into Unmanaged code (C++ / Win32) ? RRS feed

  • Question

  • Hi,

    I am working on integration of .Net controls and assemblies to my existing application.

    As a part of it, i need to use ActiveX controls created in .Net from my unmanaged code ( say C++ & Win32 )
    Even i need to control the display (width, height, resizing...)  and events of the control.

    How can we achieve this ?



    Thanks
    Rounak
    Monday, April 21, 2008 7:09 AM

Answers

All replies

  • Hi Rounak,

     

    Actually, IMHO there is no difference between using of ActiveX object written in unmanaged C++ and one written in managed C#.

     

    Monday, April 21, 2008 9:54 AM
  • Hi Vitaliy,

    thanks for reply.

    but i think we need to handle the display of the control.

    BTW,  i am not able to see my created control after registering it using  regasm usercontrol.dll

    but if i register it as a TypeLibrary using regasm usercontol.dll /tlb  then i can use it in my unmanaged application.

    is it due to the project type selected,  that is ClassLibrary.
    I have tried to create an ActiveX in C#  as a Windows Control Library, but still not able to use it in VB.

    Monday, April 21, 2008 11:15 AM
  • Did you put the DLL in the GAC?  You should, use regasm.exe /codebase if that's not practical.
    Tuesday, April 22, 2008 12:09 AM
    Moderator
  • Please check out the following references about this issue to see if they can help you in this issue:

    Exposing Windows Forms Controls as ActiveX controls

    Writing an ActiveX control in C#

     

    Thanks!

    Tuesday, April 22, 2008 12:40 AM
  • Hi
    thanks for reply.

    Yes i had put the dll in GAC using regasm.

    I found, how to use .Net ActiveX in VB from :  http://www.codeproject.com/KB/vb-interop/UsingDotNETControlsInVB6.aspx

        Changes need int .Net ActiveX Project :
     ->   In ActiveX project settings, select  ->  Register for COM Interop
     ->   in AssemblyInfo.cs  ->   set ComVisible to TRUE  ( [assembly: ComVisible(true)] )

        -> Register the DLL

        How we can use it in VB :
               ->   From Project menu, select Add Reference and select the .Net ActiveX.
               ->   Add a control in RunTime.
    Private Sub Form_Load()
    Set
    car = Controls.Add("CarControl.Car", "car", Me)
    End Sub

    Here, i can use the Activex control from .net into VB6 by adding it as a reference and then @ runtime it shows an activex Control.  
    But can i see the user defined ActiveX control that is created in .Net, while form designing itself, as other ActiveX controls (i.e. Calander Control).

    AND i think to use this control in C++/win32, i need to follow COM Interop from C++ code.  Am i right ?


    Thanks
    RounakP
    Tuesday, April 22, 2008 6:28 AM
  • AND i think to use this control in C++/win32, i need to follow COM Interop from C++ code.  Am i right ?
    Just use the interopped control like using normal COM control:
    Using a Custom ActiveX Control in MFC

    Thanks!
    Tuesday, April 22, 2008 7:34 AM