请教MFC调COM事件的问题
时间:2011-12-18
来源:互联网
因项目需要要用vc++6.0调用C#写的COM组件,本人只会C#,按标准写好COM组件但不会用VC写示例.
麻烦高手帮帮忙.给出调用事件的代码
C# COM的代码
[Guid("74623E27-B23F-4754-90B8-F7B1AEEBAA87")]
public interface ICtrlHelper
{
[DispId(1)]
string IP { get; set; }
.......
[DispId(5)]
string Test(int lineidx, string tagList, int flag);
.......
}
[Guid("9CD61034-1A39-4554-AD0F-2085D2CD34DC")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ICtrlEvent
{
....
[DispId(15)]
void OnCtrlNotice(string[] ctrlNotice, string[] getdata);
....
}
[Guid("20F7F594-F029-4cd0-A0D7-411B05459F09")]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(ICtrlEvent))]
public class CtrlHelper : ICtrlHelper
, IObjectSafety
{
....
[ComVisible(false)]
public delegate void OnGetInfoHandle(string[] ctrlNotice, string[] getdata);
/// <summary>
/// 所有系统消息
/// </summary>
public event OnCtrlNoticeHandle OnCtrlNotice;
string Test(int lineidx, string tagList, int flag)
{
....
这里触发了OnCtrlNotice事件
...
}
....
}
网上找教程演示代码现在可以调用方法了,但是事件不知道怎么接受.
以下是MFC里调用COM方法的代码,已经测试成功
void CWCSPortTestDlg::OnButton1()
{
CoInitialize(NULL);
WcsPortCOM::ICtrlHelperPtr p(__uuidof(CtrlHelper));
p->PutIP("192.168.1.11"); //初始化
MessageBox(p->Test(1,"2",1)); //调用TEST方法
CoUninitialize();
}
麻烦哪位再帮忙给出调用事件的代码,只要代码.应该没几句话的,只是我实在外行,不知道什么格式
麻烦不要贴链接,这几天我看了不下百篇了.
麻烦高手帮帮忙.给出调用事件的代码
C# COM的代码
[Guid("74623E27-B23F-4754-90B8-F7B1AEEBAA87")]
public interface ICtrlHelper
{
[DispId(1)]
string IP { get; set; }
.......
[DispId(5)]
string Test(int lineidx, string tagList, int flag);
.......
}
[Guid("9CD61034-1A39-4554-AD0F-2085D2CD34DC")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ICtrlEvent
{
....
[DispId(15)]
void OnCtrlNotice(string[] ctrlNotice, string[] getdata);
....
}
[Guid("20F7F594-F029-4cd0-A0D7-411B05459F09")]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(ICtrlEvent))]
public class CtrlHelper : ICtrlHelper
, IObjectSafety
{
....
[ComVisible(false)]
public delegate void OnGetInfoHandle(string[] ctrlNotice, string[] getdata);
/// <summary>
/// 所有系统消息
/// </summary>
public event OnCtrlNoticeHandle OnCtrlNotice;
string Test(int lineidx, string tagList, int flag)
{
....
这里触发了OnCtrlNotice事件
...
}
....
}
网上找教程演示代码现在可以调用方法了,但是事件不知道怎么接受.
以下是MFC里调用COM方法的代码,已经测试成功
void CWCSPortTestDlg::OnButton1()
{
CoInitialize(NULL);
WcsPortCOM::ICtrlHelperPtr p(__uuidof(CtrlHelper));
p->PutIP("192.168.1.11"); //初始化
MessageBox(p->Test(1,"2",1)); //调用TEST方法
CoUninitialize();
}
麻烦哪位再帮忙给出调用事件的代码,只要代码.应该没几句话的,只是我实在外行,不知道什么格式
麻烦不要贴链接,这几天我看了不下百篇了.
作者: xv84 发布时间: 2011-12-18
接收事件是什么意思?
在C#写的模块中触发的事件,不在本模块中解决吗?传递到MFC客户端解决?
在C#写的模块中触发的事件,不在本模块中解决吗?传递到MFC客户端解决?
作者: mougaidong 发布时间: 2011-12-18
相当于发布一个命令,过一段时间,COM会返回一个结果,VC要接收这个结果
作者: xv84 发布时间: 2011-12-18
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28