Publishing an event in C++/Cli

Topics: Prism v4 - WPF 4
Aug 9, 2011 at 3:51 PM


I am using Prism version 4.

I have use IEventAggregator in some of my programs made with C# wpf/mvvm and I love it.

I have an existing application mix with C#, C++/cli, and C++.

Now I am bringing IEventAggregator in this software to be more loosely coupled.

I am publishing some events very well, but when it comes to subscribe, I cannot make it work in C++/CLI.


If I do the following :


I get the following error :

CTaxRetMgr.cpp(45): error C3867: 'CalcTaxManager::CTaxRetMgr::CalcForm': function call missing argument list; use '&CalcTaxManager::CTaxRetMgr::CalcForm' to create a pointer to member

If I do create a delegate:

in .h


               delegate void CalcFormHandler(System::Object^ obj, DrTaxIdentification::FormIdentification^ FormID);

in .cpp
        EventAggregator->GetEvent<DoCalculationEvent^>()->Subscribe(gcnew CalcFormHandler(this, &CalcTaxManager::CTaxRetMgr::CalcForm));

I get the following error :

CTaxRetMgr.cpp(45): error C2664: 'Microsoft::Practices::Prism::Events::SubscriptionToken ^Microsoft::Practices::Prism::Events::CompositePresentationEvent<TPayload>::Subscribe(System::Action<T> ^)' : cannot convert parameter 1 from 'CalcTaxManager::CTaxRetMgr::CalcFormHandler ^' to 'System::Action<T> ^'
              TPayload=DrTaxIdentification::FormIdentification ^,
              T=DrTaxIdentification::FormIdentification ^
              T=DrTaxIdentification::FormIdentification ^
          No user-defined-conversion operator available, or
          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

How can I cast a Delegate to a System.Action????

Is there any example somewhere on how to subscribe to an event in C++/cli?




Aug 9, 2011 at 6:17 PM

Hi Gi,

Currently there is no official support for Prism on the C++/cli language.

For specific topics regarding C++/cli you can post a question in the Visual C++ forums:


Damian Cherubini