tags:

views:

209

answers:

1

Hi, I am using IMoniker::BindToObject function, and I have read the article on MSDN.

The article doen't say the first parameter can be NULL, but the example code on the following page uses NULL as the argument :

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);)

since I don't quite understand the use of this parameter and I don't need the extra binding information returned by the function,

I would like to ask "can the argument be NULL?".

thanks in advance.

A: 

The documentation on BindToObject suggests that you can create a bind context using CreateBindCtx and pass that:

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();

The interface only describes the behaviour that the object must support, but not how it is required to support it. On the one hand, the implementing object might require that you pass in a bind context, or it might not. Since the documentation you pointed to omits it, it is probably not required in your situation.

On the other hand, it doesn't seem to me like a big deal to create a bind context object and pass it in. You can pass in the same one to every call to BindToObject so the overhead may be small. Therefore, if you are worried that it is required, I would just do it.

1800 INFORMATION
I have seen this, but it is kind of a trouble if I have to bind a lot of objects. Because I don't need any information in pbc parameter.
I added some thoughts, nothing conclusive
1800 INFORMATION