locked
Making Forms available to VB6 using Interop Forms Toolkit via reg-free COM

    Question

  • Hi,

    I've installed the Interop Forms Toolkit 2.0 and I'm experimenting with making Forms and Controls that are usable by VB6 clients. This would be our preferred upgrade path for a large VB6 codebase.  This is working fine but I'm now trying to take it one step further and use registration-free COM (side-by-side) so that my .NET assemblies do not need registering when they're deployed. I can get this to work fine for "VB6 Interop UserControl" projects by modifying the manifest as necessary and specifying the CLSIDs of the UserControls in the project.  When you add a new UserControl to the project, constants for the relevant COM GUIDS are generated for you and the class is decorated using the ComClassAttribute.

    How do I achieve this with Forms in a "VB6 InteropForm Library" project?  Do I need to create the manifest and resource file and then manually generate GUIDS and add the constants along with the attribute for each new form I create?  This would seem to be negating the stated aim of the Interop Forms Toolkit which is to allow developers to focus on being productive rather than wrestling with the nuts and bolts of COM Interop. This leads me to suspect there's something obvious I'm missing, can anyone help me out?

    Thanks in advance,

    Colin

    Wednesday, February 22, 2012 4:20 PM

Answers

  • Hi Mike,

    I found an email address for one of the guys at MS that originally worked on the toolkit so I asked him the question. To his credit I got a quick and detailed reply.  To summarize, the InteropForms part was developed first and used a similar pattern to the Patterns and Practices CAB block where you have to decorate Forms, Methods, Properties etc with specific attributes to indicate that they should be included in the proxy classes generated and therefore visible from COM clients.  This work was then extended be a different team to include InteropControls and they decided to use a different pattern based on the ComClass attribute and anything public is automatically visible to COM clients.  The reg-free COM work was done as part of the InteropControls effort and there was no attempt to revisit InteropForms and do the same there.

    The bottom line is that it's probably possible to get InteropForms working but it would probably require modifications to the code that generates the proxies and unfortunately I don't have the time at the moment to investigate this further.  Therefore, for the time being I'm going to stick to using Regasm.

    Thanks anyway for your help.

    Colin

    • Marked as answer by Colin Baker Thursday, March 08, 2012 5:05 PM
    Thursday, March 08, 2012 5:04 PM

All replies

  • Hi Colin,

    Welcome to the MSDN Forum.

    Based on your description, it seems that you have some problem with using Interop Forms Toolkit, but what is the exactly issues? Do you have any error messages or code snippet?

    Anyway, here is a tutorial site: http://msdn.microsoft.com/en-us/vstudio/ms788241 expecially, this one should be very helpful: Best Practices to Use Visual Basic 6.0 and Visual Basic .NET Together  

    And here is a video about this topic: http://msdn.microsoft.com/en-us/vstudio/Video/bb643843 

    Visual Basic programmers will learn how to create .NET Windows Forms in Visual Studio that run in Visual Basic 6 applications using the Interop Forms Toolkit 2.0. 

    The related code can be found here: http://blogs.msdn.com/b/bethmassi/archive/2007/06/25/visual-basic-interop-video-series-is-live.aspx 

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 23, 2012 8:55 AM
    Moderator
  • Thanks for the reply Mike but I think you've misunderstood my issue.

    I can use the Interop Forms Toolkit to create a .NET Windows Form that can be used from VB6 when the .NET project is registered using RegAsm, but I want to use registration-free COM.  When creating a usercontrol project using the toolkit the manifest and resource (.rc) file required for this are created for you and when adding a new usercontrol to the project it defines the CLSID required.

    Neither of these things happen for forms projects using the toolkit. I could probably do them manually but it would be a lot of extra effort to set up the manifest and resource file correctly and then to generate the GUIDS every time I add a new form.

    Since these two project types are both part of the same toolkit and developed by the same team I'm confused as to why they work in very different ways and wonder if there's a simple way to get registration-free COM working nicely with forms projects.

    Regards,

    Colin

    Thursday, February 23, 2012 11:41 AM
  • Hi Colin,

    Sorry for misunderstanding you.

    So I want to clarify it again: You have develop a user control in VB.net, and you want to use it in your VB6 project. Now, your working way is register the user control first, then, call it in your VB6 application, but you intend to use it without register it. Am I right?

    If so, please take a look at the summary of this article: http://msdn.microsoft.com/library/ms364069(vs.80).aspx 

    A Microsoft Visual Basic 6 application can access .NET class libraries, but to do so, it must go through an interoperability layer, known as a client callable wrapper. This wraps the desired .NET class, and exposes it so that it appears as a traditional COM object, which can be used from any environment that can consume COM objects. 

    And the general way about making this wrapper is using Regasm tool to register it. And in my opinion, there is no easy way to achieve this goal.

    If I still misunderstanding anything, please feel free to follow up.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, February 24, 2012 5:56 AM
    Moderator
  • Hi Mike,

    My problem isn't with COM Interop.  I've been using Interop with standard class libraries for some time, have a pretty good understanding of it, and it's working nicely.

    More recently I've begun to expose .NET UserControls and Forms via COM Interop using the Interop Forms Toolkit 2.1.  Again this is working fine by using Regasm to register the assemblies which, as you point out, is the normal route.  The problem I've got is trying to combine this with registration-free COM, i.e. NOT using Regasm to register the assemblies and instead using manifests.

    This is not really related to the COM Interop except that 'VB6 Interop UserControl' projects from the Interop Forms Toolkit provide a few things that make life easier, such as the required manifest and resource file.  For some reason the 'VB6 InteropForm Library' project that's also installed as part of the toolkit doesn't.

    Regards,

    Colin

    Friday, February 24, 2012 8:58 AM
  • Hi Mike,

    I meant to say that the answer to the question in your first paragraph is 'yes', with the exception that I can already get this working for UserControls but not for Forms.

    There is a mechanism for using COM components without registering them first.  It's called registration-free COM or side-by-side (SxS) and is nothing to do with COM Interop per se but it's possible to leverage this mechanism with .NET assemblies and bypass having to use Regasm.

    Regards,

    Colin

    Friday, February 24, 2012 10:09 AM
  • See if the below article helps:

    http://blogs.msdn.com/b/bethmassi/archive/2007/06/27/deploying-interop-usercontrols.aspx


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, February 24, 2012 6:24 PM
  • Thanks Paul, but I can get UserControl projects working nicely with reg-free COM, it's the Forms projects I'm having trouble with.

    Regards,

    Colin

    Monday, February 27, 2012 9:13 AM
  • I don't believe it would be any different for an Interop Form Library. The CLSID for the Interop Form Library should be generated for you when you create the project. Take a look at the Assembly Information (Application tab) under the Project Properties to get the CLSID (GUID) for the Interop Form Library that you have created.

    Unless you have added other Classes or are exposing custom Class properties, additional GUIDs are probably not required for the Class module(s) and manifest.


    Paul ~~~~ Microsoft MVP (Visual Basic)


    Monday, February 27, 2012 4:19 PM
  • Hi Paul.

    A CLSID for the project is indeed created along with the project but as far as I'm aware this isn't used for registration-free COM.  In the UserControl project each control is given a CLSID and it is this that must be entered into the manifest.  The equivalent for a Forms project would therefore be that each form is given a CLSID, but this is not the case and there's no manifest created for you.

    So they definitely work differently, just create one of each project type and you'll see what I mean.

    Regards,

    Colin

    Monday, February 27, 2012 5:49 PM
  • Doesn't it beg the question though, how did the Interop Forms Library get registered during the development and testing phase? You would not see it in the References dialog in VB 6.0 if the library had not been registered during the compile process, nor would you have been able to use it from a COM host.

    Second question: Did you actually try creating a manifest for the Interop Forms Library and using the GUID? And if that didn't work, did you try adding adding a GUID/CLSID to the Class (like the user control method) and specifying that in the Interop Forms Library manifest?

    I would suggest you try both methods (if necessary).


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Monday, February 27, 2012 6:12 PM
  • Also, you might want to give the below manifest generator utility a try:

    http://mmm4vb6.atom5.com/


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Monday, February 27, 2012 6:21 PM
  • Hi Colin,

    We didn't hear from you a couple of days.

    Do you have any update?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 05, 2012 3:51 PM
    Moderator
  • Hi Mike,

    I found an email address for one of the guys at MS that originally worked on the toolkit so I asked him the question. To his credit I got a quick and detailed reply.  To summarize, the InteropForms part was developed first and used a similar pattern to the Patterns and Practices CAB block where you have to decorate Forms, Methods, Properties etc with specific attributes to indicate that they should be included in the proxy classes generated and therefore visible from COM clients.  This work was then extended be a different team to include InteropControls and they decided to use a different pattern based on the ComClass attribute and anything public is automatically visible to COM clients.  The reg-free COM work was done as part of the InteropControls effort and there was no attempt to revisit InteropForms and do the same there.

    The bottom line is that it's probably possible to get InteropForms working but it would probably require modifications to the code that generates the proxies and unfortunately I don't have the time at the moment to investigate this further.  Therefore, for the time being I'm going to stick to using Regasm.

    Thanks anyway for your help.

    Colin

    • Marked as answer by Colin Baker Thursday, March 08, 2012 5:05 PM
    Thursday, March 08, 2012 5:04 PM