如何在C#中处理COM中定义的通知
来源:互联网 发布:立体雕刻软件 编辑:程序博客网 时间:2024/04/27 19:12
如何在C#中处理COM中定义的通知
C++写法:
STDMETHODCALLTYPE Advise(
/* [in] */ IUnknown *pUnkSink,
/* [out] */ DWORD *pdwCookie) = 0
C#写法:
我想用接口 IAdviseSink来实现同样的功能?
-------------------------------------------------------------------------------------
附今天才写的C#代码:
Guid CLSID_TCSUser = new Guid("4B39D001-6F7B-11d5-8CA0-00A0245AE65C");
Guid[] iids = { new Guid("4B39D002-6F7B-11d5-8CA0-00A0245AE65C"), new Guid("4B39D005-6F7B-11d5-8CA0-00A0245AE65C") };
MULTI_QI[] amqi = ole32Ex.CoCreateInstanceEx(CLSID_TCSUser,
ClsCtx.All, "127.0.0.1", iids, RpcAuthent.None, RpcAuthor.Default, "", RpcLevel.Connect, RpcImpers.Default, "", "", "",true);
if (amqi != null)
{
//获取COM对象tt
object tt = Marshal.GetObjectForIUnknown(amqi[0].pItf);
ITCSUser iICSUser = (ITCSUser)(tt);
IConnectionPointContainer cpc ;
//获取连接点对象
IntPtr ppv;
iid_cpc = new Guid("B196B284-BAB4-101A-B69C-00AA00341D07");
Marshal.QueryInterface(amqi[0].pItf, ref iid_cpc, out ppv);
cpc = (IConnectionPointContainer)(Marshal.GetObjectForIUnknown( ppv));
IConnectionPoint cpt;
//需要处理的DCOM中定义的事件
Guid TCSUserEvents = new Guid("4B39D004-6F7B-11d5-8CA0-00A0245AE65C");
cpc.FindConnectionPoint(ref TCSUserEvents, out cpt);
eventhandler = new EventHandle();
int cookie = 0;
//写道这里就进行不下去了。
cpt.Advise((object)eventhandler, out cookie);
最后一句在C++中是下面这样写的:
// Advise ITCSUserEvents
IConnectionPointContainer* pCPC = NULL;
hr = m_pUser-> QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
_ASSERT(SUCCEEDED(hr));
hr = pCPC-> FindConnectionPoint(__uuidof(ITCSUserEvents), &m_pITCSUserCP);
_ASSERT(SUCCEEDED(hr));
pCPC-> Release();
m_iUserEventsCookie = 0;
hr = m_pITCSUserCP-> Advise(static_cast <ITCSUserEvents*> (this), &m_iUserEventsCookie );
C++写法:
STDMETHODCALLTYPE Advise(
/* [in] */ IUnknown *pUnkSink,
/* [out] */ DWORD *pdwCookie) = 0
C#写法:
我想用接口 IAdviseSink来实现同样的功能?
-------------------------------------------------------------------------------------
附今天才写的C#代码:
Guid CLSID_TCSUser = new Guid("4B39D001-6F7B-11d5-8CA0-00A0245AE65C");
Guid[] iids = { new Guid("4B39D002-6F7B-11d5-8CA0-00A0245AE65C"), new Guid("4B39D005-6F7B-11d5-8CA0-00A0245AE65C") };
MULTI_QI[] amqi = ole32Ex.CoCreateInstanceEx(CLSID_TCSUser,
ClsCtx.All, "127.0.0.1", iids, RpcAuthent.None, RpcAuthor.Default, "", RpcLevel.Connect, RpcImpers.Default, "", "", "",true);
if (amqi != null)
{
//获取COM对象tt
object tt = Marshal.GetObjectForIUnknown(amqi[0].pItf);
ITCSUser iICSUser = (ITCSUser)(tt);
IConnectionPointContainer cpc ;
//获取连接点对象
IntPtr ppv;
iid_cpc = new Guid("B196B284-BAB4-101A-B69C-00AA00341D07");
Marshal.QueryInterface(amqi[0].pItf, ref iid_cpc, out ppv);
cpc = (IConnectionPointContainer)(Marshal.GetObjectForIUnknown( ppv));
IConnectionPoint cpt;
//需要处理的DCOM中定义的事件
Guid TCSUserEvents = new Guid("4B39D004-6F7B-11d5-8CA0-00A0245AE65C");
cpc.FindConnectionPoint(ref TCSUserEvents, out cpt);
eventhandler = new EventHandle();
int cookie = 0;
//写道这里就进行不下去了。
cpt.Advise((object)eventhandler, out cookie);
最后一句在C++中是下面这样写的:
// Advise ITCSUserEvents
IConnectionPointContainer* pCPC = NULL;
hr = m_pUser-> QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
_ASSERT(SUCCEEDED(hr));
hr = pCPC-> FindConnectionPoint(__uuidof(ITCSUserEvents), &m_pITCSUserCP);
_ASSERT(SUCCEEDED(hr));
pCPC-> Release();
m_iUserEventsCookie = 0;
hr = m_pITCSUserCP-> Advise(static_cast <ITCSUserEvents*> (this), &m_iUserEventsCookie );
- 如何在C#中处理COM中定义的通知
- 如何在C#中定义动态的数组结构啊??
- 在 C# 中定义常量的方法
- 如何在 Visual C# 组件中使用 COM+ 事务
- 批处理文本字符串处理-如何在循环中定义变量
- C#中如何定义数组
- c#如何在类中定义静态变量
- 在C#中调用COM/COM+
- 在C#中定义全局变量
- 如何在Listctrl 中接收Headerctrl 的通知消息
- C#中如何处理子窗体在父窗体中显示的位置
- 如何在文本框中获取按键通知
- 如何在程序中加入Growl通知
- 在C#中使用COM的一些随想---转载的
- 如何从c++中调用c#的com组件
- Atl(COM)编程如何在idl文件中使用宏定义(如#ifndefine XXX)
- C# .NET 如何在DataGridView中最简洁的实现对单元格显示的处理
- C#中如何处理异常
- 数据结构(C#)--双向链表
- E680g手机电话本起死回生记
- WINDOWS下访问linux
- Apache配置在一个IP地址上运行多个基于域名的web站点
- 对出版工作的一些感悟
- 如何在C#中处理COM中定义的通知
- 展示过去做的虚拟现实项目,地质编录的三维演示
- grep命令
- 精通DOS批处理
- netbeans打开后自动关闭的问题
- Linux学习计划
- 线性表1
- 改变具有相应值的元素单元格或者行的颜色(GredView)
- [TDD开发的全过程] 一、设计阶段