I have a class in a Windows Runtime component (written in C #) that fires events.
I cannot figure out how to subscribe to these events in a C ++ / CX application that references the component.
C # code (in the Windows Runtime component):
public sealed class Messenger {
private EventRegistrationTokenTable<EventHandler<MessageReceivedEventArgs>> messageReceivedTokenTable;
public event EventHandler<MessageReceivedEventArgs> MessageReceived
{
add
{
return EventRegistrationTokenTable<EventHandler<MessageReceivedEventArgs>>
.GetOrCreateEventRegistrationTokenTable(ref this.messageReceivedTokenTable)
.AddEventHandler(value);
}
remove
{
EventRegistrationTokenTable<EventHandler<MessageReceivedEventArgs>>
.GetOrCreateEventRegistrationTokenTable(ref this.messageReceivedTokenTable)
.RemoveEventHandler(value);
}
}
internal void OnMessageReceived(string message, string location)
{
EventHandler<MessageReceivedEventArgs> temp =
EventRegistrationTokenTable<EventHandler<MessageReceivedEventArgs>>
.GetOrCreateEventRegistrationTokenTable(ref this.messageReceivedTokenTable)
.InvocationList;
temp(this, new MessageReceivedEventArgs(message, location));
}
}
MessageReceivedEventArgs:
public sealed class MessageReceivedEventArgs : object
{
public MessageReceivedEventArgs(string message, string location)
{
this.Message = message;
this.SenderLocation = location;
}
public string Message { get; set; }
public string SenderLocation { get; set; }
}
Note that according to MSDN, this comes from an object, not from EventArgs.
Then in C ++:
msngr = ref new Messenger();
msngr->MessageReceived += ?????????
What should be done after +=and in the appropriate method (and anywhere - in C # and / or C ++) so that I can receive messages in a C ++ application?
I tried different things, and the various compiler warnings I came across were not able to point me to a solution.
, Runtime Windows, #, ++, . . ++, #.