title: Converting the C++/CX "delegate" object over to its equivalent in C++/WinRT
body: <p>I'm new to WinRT. I'm converting my Windows UWP app written C++/CX over to C++/WinRT. I have a C++/CX <code>ref</code> class that basically does the same thing as the <code>Microsoft.VisualStudio.PlatformUI.DelegateCommand</code> class does in C#. My C++ class implements <code>ICommand</code> where the <code>Execute</code> and <code>CanExecute</code> callbacks are handled by delegates. The abbreviated code for the header file looks like this:</p>
  <pre><code>public delegate void ExecuteDelegate(Platform::Object^ parameter);
  public delegate bool CanExecuteDelegate(Platform::Object^ parameter);
  
  public ref class DelegateCommand sealed :
      Windows::UI::Xaml::DependencyObject,
      Windows::UI::Xaml::Data::INotifyPropertyChanged,
      public Windows::UI::Xaml::Input::ICommand
  {
  public:
      DelegateCommand(ExecuteDelegate^ execute, CanExecuteDelegate^ canExecute);
      .
      .
      .
  private:
      ExecuteDelegate^       m_executeDelegate = nullptr;
      CanExecuteDelegate^    m_canExecuteDelegate = nullptr;
      .
      .
      .
  };
  </code></pre>
  <p>And a typical instantiation of my <code>DelegateCommand</code> class passes a weak pointer and a function pointer into the constructor from a class that has the implementation of the <code>Execute</code> and <code>CanExecute</code> methods:</p>
  <pre><code>Commands::Instance-&gt;UndoCommand = ref new DelegateCommand(
      ref new ExecuteDelegate(this, &amp;SVGDocumentUserControl::ExecuteUndoCommand),
      ref new CanExecuteDelegate(this, &amp;SVGDocumentUserControl::CanExecuteUndoCommand));
  </code></pre>
  <p>I'm sure this is a simple question, but it is unclear to me from what I have read, so exactly how would one define the two C++/CX delegates in C++/WinRT?</p>
  <pre><code>public delegate void ExecuteDelegate(Platform::Object^ parameter);
  public delegate bool CanExecuteDelegate(Platform::Object^ parameter);
  </code></pre>
  <p>[Edit: I am also scratching my head on how to define the constructor's function pointers in the *.idl file.]</p>
  <p>Thank you for your patience.</p>