使用c++/cli并在c#中使用它的事件处理
event handling using c++/cli and using it in c#
-每当调用方法showmessage时,我都想引发一个事件。我想在C#密码
-我已经为它写了事件。
-我在Initialize函数中所做的将委托与功能显示消息
-如何在c#中使用此事件
C++/CLI
delegate void progressmsgdisplay(System::String ^ message);
progressmsgdisplay ^ progressMsgNotify;
void Mclass::ShowMessage(System::String ^ message)
{
MessageBox(NULL, m_msg, m_box, NULL);
notify(message);
}
event progressmsgdisplay ^ notify
{
void add(progressmsgdisplay ^ d)
{
progressMsgNotify += d;
}
void remove(progressmsgdisplay ^ d)
{
progressMsgNotify -= d;
}
void raise(System::String ^ msg)
{
progressmsgdisplay ^ tmp = progressMsgNotify;
if (tmp)
{
tmp->Invoke(msg);
}
}
}
//void Mclass::Initialize(System::String ^ strProgressMsg)
//{
// progressMsgNotify=gcnew progressmsgdisplay(this,&Mclass::ShowMessage);
//}
-Mclass是在其中声明和定义上述所有的类的名称
C#
void display(string progressnotification)
{
Console.Out.WriteLine(progressnotification);
}
void initialize()
{
first = new Mclass();
first.notify()+=display;
}
这就成功了
为什么不能在c++/cli中使用EventHandler类并在c#中订阅它
//C++/CLI
public ref class SomeClass
{
public:
event EventHandler^ someEvent;
}
//C#
class Program
{
static void Main(string[] args)
{
SomeClass testclass = new SomeClass();
testclass.someEvent += someEventHandler;
}
private void someEventHandler(Object obj, EventArgs args)
{
}
}
我还没试过这个。但我想值得一试。
相关文章:
- 给定顺序中的事件处理
- C++事件系统 - 多态事件和事件处理程序
- wxWidgets 拖放文件事件处理程序初始化问题(无效static_cast)
- 更好的事件处理机制?
- 如何将IEnumerable与Process.Start的输出事件处理程序一起使用?
- "动态创建的事件处理程序"复选框
- Wxwidgets - 如何添加调整大小事件处理程序以使"X"绘图随窗口调整大小?
- Qt 键按事件处理程序仅在按下 ctrl、alt 或 shift 键时做出反应
- 类成员作为 C++ 中 C 样式事件的事件处理程序
- C 设计事件处理程序类
- 将托管事件处理程序传递给 Linux 中的非托管代码
- 如何在 c++ linux 中创建事件处理程序
- 解除 lambda 事件处理程序的绑定
- 这是MFC C 中单个选择的ComboBox的事件处理程序
- 审核的实时事件处理 C/C++
- 指纹读取器 - 从 C# 代码创建事件处理程序到C++的问题
- 为什么我的Windows控制台关闭事件处理程序超时
- 无法让 matplotlib 事件处理程序与 Boost.Python 一起工作
- 事件处理程序是Embarcadero C++Builder中的重入程序吗
- QTSCXML状态机中的事件处理