3

I have a VB6 class that needs to implement an interface which I created in C#. I have been able to succesfully implement all of the properties of the interface in my vb6 class over COM, but have not been able to implement the event that it has. If I understand correctly, I will need to have the equivalent of the add and remove accessors defined to register consumers of the event, but I cannot get VB6 to accept the interface with the event defined. I am setting the InterfaceType of the class to InterfaceIsIDispatch, but still get the error "Bad interface for Implements: method has underscore in name" when I try to compile. The interface does not define any methods, and neither the properties nor the event have any underscores.

Here is the interface definition

namespace AV8B.Overlay
{
   [ComVisible(true)]
   [Guid("89519DCE-86D6-4962-8CEA-450F2AB31B4E")]
   public delegate void OverlaySymbolPropertyChangedEventHandler(object sender, OverlaySymbolPropertyChangedEventArgs e);

   [ComVisible(true)]
   [Guid("9A59EF10-B688-4af9-8C21-FB95C7ED699A")]
   public class OverlaySymbolPropertyChangedEventArgs : PropertyChangedEventArgs
   {
      OverlaySymbolPropertyChangedEventArgs(string propertyName) : base(propertyName) { }
   }

   [ComVisible(true)]
   [Guid("379B179C-85FA-4efb-8198-D1A4C80D645A")]
   public interface IOverlaySymbol : INotifyPropertyChanged
   {
      bool SelectedForProcessing { get; set; }
      int SymbolNumber { get; }
      string SymbolType { get; }
      double Latitude { get; }
      double Longitude { get; }
      string Color { get; }
      int Size { get; }

      /// <summary>
      /// This method fires the PropertyChanged event.
      /// </summary>
      void NotifyPropertyChanged();

      /// <summary>
      /// The event that fires when a property changes.
      /// </summary>
      new event OverlaySymbolPropertyChangedEventHandler PropertyChanged;
   }
}

The goal behind this is to place existing VB objects that implement this interface into a binding list which will be attached to a list grid view. The list grid view needs to know when the properties of its items change so it can update accordingly.

aquaherd
  • 444
  • 4
  • 12
  • The COM interface generated might contain underscores, even if you don't use it explicitly in your C# interface definition. A former colleague achieved what your trying to do (data binding COM objects into .NET GUI) but the COM implementation was in C++, not in VB6, because VB6 only offers a reduced set of COM features. – Seb Sep 30 '11 at 08:01

4 Answers4

1

INotifyPropertyChanged is mostly used with property bindings just as you described.

Specifically VB6 controls (and ActiveX controls in general) have this mostly already built-in, but its a different interface.

You could perhaps work it the other way round: Your grid accepts .Net Controls with INotifyPropertyChanged and ActiveX controls with INotifyPropertySink. Some relevant helpers may be:

Thumbs up!

Community
  • 1
  • 1
aquaherd
  • 444
  • 4
  • 12
0

it sound very complex. Maybe one better approach will be

1)Create one implementation of your interface it on .net and use one pattern how "Active Record" para behavior 2)After create one wrapper for that with methods simples how

entityChange(parameters) saveChange(parameters) SaveAll CancellAll

from .net you can throw events to vb6 (for update grid or do something)

here examples list http://www.elguille.info/NET/servidorNETparaCOM/servidorNETparaCOM.htm

mix all and do test

Carlos Cocom
  • 937
  • 1
  • 8
  • 23
0

There is no way to implement events in VB6, even when using native VB6 class that has events declared.

What you can do to handle this impedance is to pass a callback interface to VB6 objects and implement a proxy in .Net that raises your events in callback methods implementation. The proxy will obviously need to forward properties/methods too.

wqw
  • 11,771
  • 1
  • 33
  • 41
0

An option is to use standard COM events which handle the interface, subscribe, unsubscrie, etc for you.

If you just have a single object, then normal event/delegate pairs will be exposed as COM events, but for more complex interfaces and events, you need to create your event sink interface and asociate it with the each class itself using:

[System.Runtime.InteropServices.ComSourceInterfaces(typeof(ISystem_COMEventSink))]
Deanna
  • 23,876
  • 7
  • 71
  • 156