判斷物件支援哪一個介面
[與此頁面相關聯的功能,自定義檔案和串流處理程式,是舊版功能。 MediaStreamSource 類別已取代它。 MediaStreamSource 類別 已針對 Windows 10 和 Windows 11 優化。 Microsoft強烈建議新程式代碼盡可能使用 MediaStreamSource 類別,而不是 自定義檔案和串流處理程式。 Microsoft建議使用舊版 API 的現有程式代碼,盡可能改寫成使用新的 API。]
QueryInterface 方法可讓應用程式查詢物件,以判斷支援哪些介面。 範例應用程式會將 ppv 指標設定為目前介面。
STDMETHODIMP CAVIFileCF::QueryInterface(
const IID FAR& iid,
void FAR* FAR* ppv)
{
if (iid == IID_IUnknown)
*ppv = this; // set the interface pointer
// to this instance
else if (iid == IID_IClassFactory)
*ppv = this; // second chance to set the
// interface pointer to this
// instance
else
return ResultFromScode(E_NOINTERFACE);
AddRef(); //Increment the reference count
return NULL;
}