代码之家  ›  专栏  ›  技术社区  ›  ken

COM:IMoniker::BindToObject的IBindCtx*参数是否可以为空?

  •  0
  • ken  · 技术社区  · 17 年前

    我正在使用IMoniker::BindToObject函数,我已经阅读了有关MSDN的文章。

    http://msdn.microsoft.com/en-us/library/dd407292%28VS.85%29.aspx

    (hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);)
    (hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter, (void**)&pFilter);)
    

    因为我不太了解这个参数的用法,也不需要函数返回额外的绑定信息,

    我想问“这个参数可以是空的吗?”。

    提前谢谢。

    1 回复  |  直到 13 年前
        1
  •  1
  •   1800 INFORMATION    17 年前

    这个 documentation on BindToObject 建议您可以使用创建绑定上下文 CreateBindCtx 并通过:

    HRESULT hr;       // An error code
    IMoniker * pMnk;  // A previously acquired interface moniker
    
    // Obtain an IBindCtx interface.
    IBindCtx * pbc; 
    hr = CreateBindCtx(NULL, &pbc); 
    if (FAILED(hr)) exit(0);  // Handle errors here. 
    
    // Obtain an implementation of pCellRange. 
    ICellRange * pCellRange; 
    hr = pMnk->BindToObject(pbc, NULL, IID_ICellRange, &pCellRange); 
    if (FAILED(hr)) exit(0);  // Handle errors here. 
    
    // Use pCellRange here. 
    
    // Release interfaces after use. 
    pbc->Release(); 
    pCellRange->Release(); 
    

    接口仅描述对象必须支持的行为,而不描述如何需要它来支持它。一方面,实现对象可能需要在绑定上下文中传递,也可能不需要。由于您所指的文档省略了它,因此在您的情况下可能不需要它。

    另一方面,在我看来,创建一个绑定上下文对象并将其传入并没有什么大不了的。您可以将相同的消息传递给每个呼叫 BindToObject