title: How to subscribe to events raised within a Windows Runtime Component in C++/CX?
body: <p>I have an class in a Windows Runtime Component (written in C#) that raises events.<br>
  I cannot work out how to subscribe to these events in a C++/CX app that references the component. </p>
  
  <p>The C# code (in the Windows Runtime Component):</p>
  
  <pre><code>public sealed class Messenger {
  
      private EventRegistrationTokenTable&lt;EventHandler&lt;MessageReceivedEventArgs&gt;&gt; messageReceivedTokenTable;
  
  
  public event EventHandler&lt;MessageReceivedEventArgs&gt; MessageReceived
  {
      add
      {
          return EventRegistrationTokenTable&lt;EventHandler&lt;MessageReceivedEventArgs&gt;&gt;
              .GetOrCreateEventRegistrationTokenTable(ref this.messageReceivedTokenTable)
              .AddEventHandler(value);
      }
  
      remove
      {
          EventRegistrationTokenTable&lt;EventHandler&lt;MessageReceivedEventArgs&gt;&gt;
              .GetOrCreateEventRegistrationTokenTable(ref this.messageReceivedTokenTable)
              .RemoveEventHandler(value);
      }
  }
  
  internal void OnMessageReceived(string message, string location)
  {
      EventHandler&lt;MessageReceivedEventArgs&gt; temp =
          EventRegistrationTokenTable&lt;EventHandler&lt;MessageReceivedEventArgs&gt;&gt;
          .GetOrCreateEventRegistrationTokenTable(ref this.messageReceivedTokenTable)
          .InvocationList;
  
      temp(this, new MessageReceivedEventArgs(message, location));
  }
  
  }
  </code></pre>
  
  <p><code>MessageReceivedEventArgs</code> is:</p>
  
  <pre><code>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; }
  }
  </code></pre>
  
  <p>Note that as per <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br230301.aspx#DeclaringRaisingEvents" rel="nofollow">MSDN</a> this descends from object and not EventArgs.</p>
  
  <p>Then in C++:</p>
  
  <pre><code>msngr = ref new Messenger();
  
  msngr-&gt;MessageReceived += ?????????
  </code></pre>
  
  <p>What should go after the <code>+=</code> and in the relevant method (and anywhere else - in C# and/or C++) so that I can receive the messages in the C++ app?</p>
  
  <p>I've tried various things and the various compiler warnings I've encountered have been unable to point me to a solution.</p>
  
  <p>All examples I've found of using a Windows Runtime Component written in C# but consumed in a C++ app have been trivial and only show using properties and calling methods. Both of which I can do without problem. I'm after an example of subscribing to an event in C++ that is raised in C#.</p>