In a c# assembly I’ve got a global prism CompositeCommand to subscribe to like this:
private static readonly CompositeCommand __myCommand = new CompositeCommand();
public static CompositeCommand MyCommand
{
get { return _myCommand; }
}
From c# I can subscribe to this command using:
[...].MyCommand.RegisterCommand(new DelegateCommand<MyClass>((c) => c.Something()));
My problem: I need to subscribe to the command from managed c++, and I got no idea how the function signature needs to be to be used in DelegateCommand. Most of the time I get errors like:
error C2664: ‘Microsoft::Practices::Prism::Commands::DelegateCommand::DelegateCommand(System::Action ^)’: conversion of parameter 1 from ‘void (__clrcall *)(MyNameSpace::MyClass ^)’ in ‘System::Action ^’ not possible.
How do I subscribe to a c# command? Or is there some other way to listen to an event (I can replace the CompositeCommand with something different).
Thanks!
I’m going to assume that you’re using managed C++ – anything else, and there’s bigger issues to worry about.
It looks like you’re getting linking errors to your C# type. As such, I don’t think the issue is related to any problems with Prism. In order for the C++ managed compiler to link to your C# assembly, you need to produce the C# assembly with an XML documentation file (see the Build tab in your properties). Is that enabled in your project?
I used the following as a very simple proof of concept, where TestObject is defined in the C# assembly referenced by the C++ DLL. This compiled without any issues.
Header file:
Implementation: