EDN Admin
Well-known member
just to understand the COM code I am working with I would like to code QueryInterface without using the QITABENT macro and QISearch function. My attempt to do that is not working. How to manually do what QITAB, QITABENT and QISearch do?
here is the QueryInterface function that uses QISearch:
<pre class="prettyprint IFACEMETHODIMP MRecipePreviewHandler::QueryInterface(REFIID riid, void **ppv)
{
*ppv = NULL;
static const QITAB qit[] =
{
QITABENT(MRecipePreviewHandler, IObjectWithSite),
QITABENT(MRecipePreviewHandler, IOleWindow),
QITABENT(MRecipePreviewHandler, IInitializeWithStream),
QITABENT(MRecipePreviewHandler, IPreviewHandler),
{ 0 },
};
return QISearch(this, qit, riid, ppv);
}[/code]
<br/>
and my replacement that does not work:
<pre class="prettyprint IFACEMETHODIMP MRecipePreviewHandler::QueryInterface(REFIID riid, void **ppv)
{
*ppv = NULL;
if ( riid == __uuidof(IUnknown))<br/> {<br/> *ppv = this ;<br/> AddRef( ) ;<br/> return S_OK ;<br/> } if ( riid == __uuidof(IObjectWithSite))
{
*ppv = this ;
AddRef( ) ;
return S_OK ;
}
if ( riid == __uuidof(IOleWindow))
{
*ppv = this ;
AddRef( ) ;
return S_OK ;
}
if ( riid == __uuidof(IInitializeWithStream))
{
*ppv = this ;
AddRef( ) ;
return S_OK ;
}
if ( riid == __uuidof(IPreviewHandler))
{
*ppv = this ;
AddRef( ) ;
return S_OK ;
}
*ppv = NULL ;
return E_NOINTERFACE ;
} [/code]
<br/>
<br/>
View the full article
here is the QueryInterface function that uses QISearch:
<pre class="prettyprint IFACEMETHODIMP MRecipePreviewHandler::QueryInterface(REFIID riid, void **ppv)
{
*ppv = NULL;
static const QITAB qit[] =
{
QITABENT(MRecipePreviewHandler, IObjectWithSite),
QITABENT(MRecipePreviewHandler, IOleWindow),
QITABENT(MRecipePreviewHandler, IInitializeWithStream),
QITABENT(MRecipePreviewHandler, IPreviewHandler),
{ 0 },
};
return QISearch(this, qit, riid, ppv);
}[/code]
<br/>
and my replacement that does not work:
<pre class="prettyprint IFACEMETHODIMP MRecipePreviewHandler::QueryInterface(REFIID riid, void **ppv)
{
*ppv = NULL;
if ( riid == __uuidof(IUnknown))<br/> {<br/> *ppv = this ;<br/> AddRef( ) ;<br/> return S_OK ;<br/> } if ( riid == __uuidof(IObjectWithSite))
{
*ppv = this ;
AddRef( ) ;
return S_OK ;
}
if ( riid == __uuidof(IOleWindow))
{
*ppv = this ;
AddRef( ) ;
return S_OK ;
}
if ( riid == __uuidof(IInitializeWithStream))
{
*ppv = this ;
AddRef( ) ;
return S_OK ;
}
if ( riid == __uuidof(IPreviewHandler))
{
*ppv = this ;
AddRef( ) ;
return S_OK ;
}
*ppv = NULL ;
return E_NOINTERFACE ;
} [/code]
<br/>
<br/>
View the full article