1

Mobile Broadband API 的文档中,它说:

以下过程描述了如何注册通知。

1.通过在IMbnInterfaceManager >对象上调用QueryInterface来获取IConnectionPointContainer接口。
2.在返回的接口上调用FindConnectionPoint,将IID_IMbnPinEvents传递给riid。
3. 在返回的连接点上调用 Advise,并将一个指向实现 IMbnPinEvents 的 > 对象上的 IUnknown 接口的指针传递给 pUnk。

可以通过在步骤 2 中返回的连接点上调用 Unadvise 来终止通知。

我有一些执行前 3 个步骤的代码,它成功注册了 MBN 事件。但是,现在我需要暂时取消注册以接收这些事件。
因此,在以 COM 异常结束的几次第一次尝试之后,我尝试了以下代码(使用 try/catch 块):

//First get the notifications

public void RegisterEvent(object iUnk, Guid guid, out uint storedTag)
{
IConnectionPoint icp = null;
Guid curGuid = guid;
storedTag = 0;
if ((curGuid == typeof(IMbnInterfaceManagerEvents).GUID) )              
{
  // For this event, the connection point is defined on the interface manager object
  m_InterfaceManagerCPC.FindConnectionPoint(ref curGuid, out icp);
  // Call Advise on the connection point to register
  icp.Advise(iUnk, out storedTag);
  //Save the IConnectionPoint object
  interfaceManagerCP = icp;

}

//Now deregister the events

public void DeregisterEvent(Guid guid, uint storedTag)
{
IConnectionPoint icp = null;
Guid curGuid = guid;

// Find the appropriate connection point to call Unadvise on
if ((curGuid == typeof(IMbnInterfaceManagerEvents).GUID) )              
{
  // Call Unadvise on the saved connection point to de-register
  interfaceManagerCP.Unadvise(storedTag);
}

当我运行此代码时,我没有收到 MBN 的错误或异常。但是事件处理程序没有被取消注册。我仍然可以在日志文件中看到 MBN 事件到达并被处理。

谁能告诉我我错过了什么?谢谢你。

4

1 回答 1

0

I think I figured out the problem. I have many different types of GUIDs, and I thought they all used the same IConnectionPoint, so I saved it to the same object in the RegisterEvent function.

When I tried creating a new IConnectionPoint object for each GUID, and saving each IConnectionPoint separately, the DeregisterEvent function also worked properly.

于 2013-05-02T13:50:12.043 回答