Really pulling my hair out with this one...
I have a C# project with an interface defined as:
/* Externally Accessible API */
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ISerial
{
[DispId(1)]
bool Startup();
[DispId(2)]
bool Shutdown();
[DispId(3)]
bool UserInput_FloorButton(int floor_number);
[DispId(4)]
bool Initialize();
}
/* Externally Accesssible Event API */
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ISerialEvent
{
[DispId(5)]
void DataEvent();
}
[ComSourceInterfaces(typeof(ISerialEvent), typeof(ISerial))]
[ClassInterface(ClassInterfaceType.None)]
public class SerialIface : ISerial
{
public delegate void DataEvent();
public event DataEvent dEvent;
public bool Initialize()
{
//testing the event callback
if (dEvent != null)
{
dEvent();
}
}
...
}
And the VB6 code looks like:
Private WithEvents objSerial As SerialIface
Private Sub objSerial_DataEvent()
'do something happy'
End Sub
Public Sub Class_Initialize()
Set objSerial = New SerialIface '<---this is the line that fails'
Call objSerial.Initialize '<--Initialize would trigger DataEvent, if it got this far'
End Sub
Well, the normal API-type functions appear to be working (if I declare objSerial without the WithEvents keyword), but I can't for the life of me get the "DataEvent" to work. It fails with the "object or class does not support the set of events" message.
I'd originally lumped the two interfaces together, but then C# complained that DataEvent was not defined in the class. The way it is currently, I am able to view all of the APIs and the one event perfectly in the VB6 object browser -- everything looks like it's there... I just can't make it actually work!
I'm sure I'm missing something obvious or doing something stupid -- but I'm new to the whole interop business, so it's just escaping me entirely.
Help!