从 c++ 订阅 c# CompositeCommand
在 ac# 程序集中,我有一个全局棱镜 CompositeCommand 可以订阅,如下所示:
private static readonly CompositeCommand __myCommand = new CompositeCommand();
public static CompositeCommand MyCommand
{
get { return _myCommand; }
}
从 c# 我可以使用以下方式订阅此命令:
[...].MyCommand.RegisterCommand(new DelegateCommand<MyClass>((c) => c.Something()));
我的问题:我需要从托管 c++ 订阅该命令,我不知道该函数如何签名需要在 DelegateCommand 中使用。大多数时候我会收到如下错误:
error C2664: 'Microsoft::Practices::Prism::Commands::DelegateCommand::DelegateCommand(System::Action ^)': conversion ofparameter 1 from 'void (__clrcall *)( “System::Action ^”中的“MyNameSpace::MyClass ^)”不可能。
如何订阅 ac# 命令?或者是否有其他方法来监听事件(我可以用不同的东西替换 CompositeCommand)。
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您正在使用托管 C++ - 其他任何东西,并且还有更大的问题需要担心。
您似乎遇到了与 C# 类型的链接错误。因此,我认为该问题与 Prism 的任何问题无关。为了使 C++ 托管编译器链接到 C# 程序集,您需要生成带有 XML 文档文件的 C# 程序集(请参阅属性中的“生成”选项卡)。您的项目中启用了该功能吗?
我使用以下内容作为一个非常简单的概念证明,其中 TestObject 是在 C++ DLL 引用的 C# 程序集中定义的。这编译没有任何问题。
头文件:
实现:
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: