none
VB6 - c# Com Interop

    Question

  • Was wondeirng could someone help with this issue.

    I have c# dll that i have turned com interop on.
       When registered it creates the tlb file successfully. I have a number of vb6 exe's that reference this tlb. The problem is that any time i change the c# dll and register i have to recompile all vb6 exe's. Does anyone know why this is happening?

    Monday, April 30, 2007 8:00 PM

Answers

  • Any changes you make to the C# code that changes the public interfaces of the classes you are exporting will generate a new GUID and break binary compatibility. This will mean updating the references in VB6 and rebuilding that as well. If you aren't changing the public interface the export should maintain the same GUID, but it's never guaranteed. You can force your classes to use a GUID by putting the Guid attribute with the classes in question. If you do change the public interface for your classes and don't change the Guid, expect unexpected behaviour.

    I.e.

    [Guid("9E9E9E9E-9E9E9-9E9E9-9E9E-9E9E9E9E9E9E")]

    Where the text is a Guid you've generated and will use for that class.

    Monday, April 30, 2007 10:01 PM
  • Another solution: How to use a .net dll in VB6

     

    When we use .NET UserControl in VB6, the .NET UserControl is compiled as a COM. To expose the events of the UserControl, we need to pack the events to be exposed into an interface, which is applied the InterfaceTypeAttribute and then apply this interface to the control class. The following is a sample. 

    Code Snippet

    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]

        public interface IMyControlCOMEvents

        {

            [DispId(0x60020000)]

            void MyEvent();

        }

     

    [ComSourceInterfaces(typeof(IMyControlCOMEvents))]

        public partial class MyControl  : UserControl

        {

             .........

         }

     

    Likewise, there is a Visual Basic example in the following link that shows a managed server as the event source and a COM client as the event sink. The managed server declares ButtonEvents as an event sink interface and connects the interface to the Button class. The unmanaged client creates an instance of the Button class and implements the event sink interface.

    Please read the article and try the sample code: How to: Raise Events Handled by a COM Sink 

    http://msdn2.microsoft.com/en-us/library/dd8bf0x3.aspx

     

    Here is one referenced thread how to call dotnetUsercontrol events in vb6.0 application?

    Thursday, May 03, 2007 6:25 AM

All replies

  • Any changes you make to the C# code that changes the public interfaces of the classes you are exporting will generate a new GUID and break binary compatibility. This will mean updating the references in VB6 and rebuilding that as well. If you aren't changing the public interface the export should maintain the same GUID, but it's never guaranteed. You can force your classes to use a GUID by putting the Guid attribute with the classes in question. If you do change the public interface for your classes and don't change the Guid, expect unexpected behaviour.

    I.e.

    [Guid("9E9E9E9E-9E9E9-9E9E9-9E9E-9E9E9E9E9E9E")]

    Where the text is a Guid you've generated and will use for that class.

    Monday, April 30, 2007 10:01 PM
  • Another solution: How to use a .net dll in VB6

     

    When we use .NET UserControl in VB6, the .NET UserControl is compiled as a COM. To expose the events of the UserControl, we need to pack the events to be exposed into an interface, which is applied the InterfaceTypeAttribute and then apply this interface to the control class. The following is a sample. 

    Code Snippet

    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]

        public interface IMyControlCOMEvents

        {

            [DispId(0x60020000)]

            void MyEvent();

        }

     

    [ComSourceInterfaces(typeof(IMyControlCOMEvents))]

        public partial class MyControl  : UserControl

        {

             .........

         }

     

    Likewise, there is a Visual Basic example in the following link that shows a managed server as the event source and a COM client as the event sink. The managed server declares ButtonEvents as an event sink interface and connects the interface to the Button class. The unmanaged client creates an instance of the Button class and implements the event sink interface.

    Please read the article and try the sample code: How to: Raise Events Handled by a COM Sink 

    http://msdn2.microsoft.com/en-us/library/dd8bf0x3.aspx

     

    Here is one referenced thread how to call dotnetUsercontrol events in vb6.0 application?

    Thursday, May 03, 2007 6:25 AM