none
hosting a C# user control to VB6 or MFC 6.0 RRS feed

  • Question

  •  

    Hi ,

    please refer to link about

    http://msdn.microsoft.com/en-us/library/aa290364(VS.71).aspx about "To create a custom tool window".

    objControl = (VSUserControlHostLib.IVSUserControlHostCtl)objTemp;
    objControl.HostUserControl(asm.Location,    "ControlClassHere");

     

    now I want to use this method (HostUserControl) to host C# user control in VB6(or mfc 6.0)

     

    Is it possible to use VSUserControlHost 'Shim' control (which is used to host a .NET UserControl) to host my graphical C# control to host on VB6?

     

    I have written following VB6 code.

    Dim obj As VSUserControlHostLibCtl.VSUserControlHostCtl
    Dim obj1 As Object

    Set obj1 = obj.HostUserControl(assemblypath,progid)

     

    but it is not working.

     

    Is there any other shim control provide by microsoft?

     

    detail of my problem is at

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3304212&SiteID=1

     

    Many thanks and regars,

    Thursday, May 8, 2008 1:40 PM

Answers

  • dipak22101980,

     

    Based on your post, in order to use the managed user control correctly in unmanaged VB6 project, there is the COM wrapper class you have to use for the Interop issue.

     

    As far as I've known, there is Interop Forms Toolkit 2.0 that simplifies the process of displaying .NET forms and controls in a Visual Basic 6 application. Your .NET project is developed in C#, I would like to provide you the C# Interop Form Toolkit from CodeProject website.

     

    The Interop Forms Toolkit 2.0 Tutorial article can help you further on this Interop toolkit issue.

     

    If there is any further problem, please feel free to reply.

     

    Hope that can provide you some idea.

    Tuesday, May 13, 2008 3:20 AM
  • Hi,

     

    As far as I've known, in order to use the managed .NET component, you could firstly expose the .NET assembly as the ActiveX component, then use the ActiveX component in your MFC application. The article Leveraging the .NET Framework Inside an MFC Application can help you with an example.

    Monday, May 19, 2008 8:31 AM

All replies

  • dipak22101980,

     

    Based on your post, in order to use the managed user control correctly in unmanaged VB6 project, there is the COM wrapper class you have to use for the Interop issue.

     

    As far as I've known, there is Interop Forms Toolkit 2.0 that simplifies the process of displaying .NET forms and controls in a Visual Basic 6 application. Your .NET project is developed in C#, I would like to provide you the C# Interop Form Toolkit from CodeProject website.

     

    The Interop Forms Toolkit 2.0 Tutorial article can help you further on this Interop toolkit issue.

     

    If there is any further problem, please feel free to reply.

     

    Hope that can provide you some idea.

    Tuesday, May 13, 2008 3:20 AM
  • Hi,

    Thanks for the answer!!

     

    is there any toolkit for MFC 6.0,

    so that i can host .net user control in legacy MFC  application.

     

    many thanks and regards,

    Monday, May 19, 2008 7:36 AM
  • Hi,

    Thanks for the answer!!

     

    is there any toolkit for MFC 6.0,

    so that i can host .net user control in legacy MFC  application.

     

    Is Microsoft is planning to release any similar toolkit in future?

     

    many thanks and regards,

    Monday, May 19, 2008 7:37 AM
  • Hi,

     

    As far as I've known, in order to use the managed .NET component, you could firstly expose the .NET assembly as the ActiveX component, then use the ActiveX component in your MFC application. The article Leveraging the .NET Framework Inside an MFC Application can help you with an example.

    Monday, May 19, 2008 8:31 AM
  • ok, I will try it out.

     

    Shukriya!!(In HINDI it means "thank u")

    Tuesday, May 20, 2008 4:51 AM
  • hi,

    using interop forms toolkit, we can use .net usercontrol in VB6. that is fine.

    can I create activex control(ocx) in VB from .net user control ?

    suppose I am able to create ocx then i will use this ocx in my legacy MFC application.

    please comment on this.

    many thanks and regards,

     

    Wednesday, May 21, 2008 3:53 PM
  • dipak,

     

    Thanks again for your question. I would like to comment as follows:

     

    1. The .NET user control should be registered using Assembly Registration tool (RegAsm.exe) to read the metadata within an assembly and adds the necessary entries to the registry, which allows COM clients to create .NET Framework classes transparently.

     

    2. It is known that .NET assembly doesn't contain a type library. Type Library Exporter(Tlbexp.exe)generates a type library that contains definitions of the types defined in the assembly. Applications such as Visual Basic 6.0 can use the generated type library to bind to the .NET types defined in the assembly.

     

    Hope that helps.

    Thursday, May 22, 2008 7:10 AM