1)在COM中注册一个消息
RegisterWindowMessage("MSG_NEWDATASOURCE")
2)在C#中也注册同一个消息
[DllImport("user32.dll")]
static extern uint RegisterWindowMessage(string lpString);
uint msgNewDataSource = RegisterWindowMessage("MSG_NEWDATASOURCE");
3)重载消息处理函数
protected override void WndProc(ref Message m)
{
if (m.Msg == (msgNewDataSource))
{
MessageBox.Show("MSG_NEWDATASOURCE Message from COM");
}
else
{
base.WndProc(ref m);
}
}
RegisterWindowMessage("MSG_NEWDATASOURCE")
2)在C#中也注册同一个消息
[DllImport("user32.dll")]
static extern uint RegisterWindowMessage(string lpString);
uint msgNewDataSource = RegisterWindowMessage("MSG_NEWDATASOURCE");
3)重载消息处理函数
protected override void WndProc(ref Message m)
{
if (m.Msg == (msgNewDataSource))
{
MessageBox.Show("MSG_NEWDATASOURCE Message from COM");
}
else
{
base.WndProc(ref m);
}
}
跨COM与C#的消息传递
本文介绍如何在COM组件与C#应用间通过注册相同的消息名称实现跨平台消息传递。具体步骤包括:1)在COM中注册消息;2)在C#中使用DllImport注册同一消息;3)重载消息处理函数以实现特定的功能响应。
6073

被折叠的 条评论
为什么被折叠?



