gpt4 book ai didi

c++ - 直接显示过滤器的 CoCreateInstance 返回 E_NOINTERFACE

转载 作者:行者123 更新时间:2023-11-28 00:33:05 29 4
gpt4 key购买 nike

我已经成功编译并注册了一个直接显示过滤器。现在我想在我的代码中使用它。但是对 COCreateInstance 的调用返回错误代码 E_NOINTERFACE。

这是我的过滤器的注册码

 #include "MyFilter.h"
#include <aviriff.h>
static WCHAR g_wszName[] = L"MyFilter";
CFactoryTemplate g_Templates[] =
{
{
g_wszName,
&CLSID_MyFilter,
MyFilter::CreateInstance,
NULL,
NULL
}
};

int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]);


// Declare media type information.
FOURCCMap fccMap = FCC('MRLE');
REGPINTYPES sudInputTypes = { &MEDIATYPE_Video, &GUID_NULL };
REGPINTYPES sudOutputTypes = { &MEDIATYPE_Video, (GUID*)&fccMap };

// Declare pin information.
REGFILTERPINS sudPinReg[] = {
// Input pin.
{ TEXT("PinInput0"), FALSE, // Rendered?
FALSE, // Output?
FALSE, // Zero?
FALSE, // Many?
0, 0,
1, &sudInputTypes // Media types.
},
{ TEXT("PinInput1"), FALSE,
FALSE,
FALSE,
FALSE,
0, 0, 1, &sudInputTypes
},
{
TEXT("PinInput2"), FALSE,
FALSE,
FALSE,
FALSE,
0, 0, 1, &sudInputTypes
},
// Output pin.
{ 0, FALSE, // Rendered?
TRUE, // Output?
FALSE, // Zero?
FALSE, // Many?
0, 0,
1, &sudOutputTypes // Media types.
}
};

// Declare filter information.
REGFILTER2 rf2FilterReg = {
1, // Version number.
MERIT_DO_NOT_USE, // Merit.
4, // Number of pins.
sudPinReg // Pointer to pin information.
};

STDAPI DllRegisterServer(void)
{
HRESULT hr = AMovieDllRegisterServer2(TRUE);
if (FAILED(hr))
{
return hr;
}
IFilterMapper2 *pFM2 = NULL;
hr = CoCreateInstance(CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
IID_IFilterMapper2, (void **)&pFM2);
if (SUCCEEDED(hr))
{
hr = pFM2->RegisterFilter(
CLSID_MyFilter, // Filter CLSID.
g_wszName, // Filter name.
NULL, // Device moniker.
&CLSID_VideoCompressorCategory, // Video compressor category.
g_wszName, // Instance data.
&rf2FilterReg // Filter information.
);
pFM2->Release();
}
return hr;
}

STDAPI DllUnregisterServer()
{
HRESULT hr = AMovieDllRegisterServer2(FALSE);
if (FAILED(hr))
{
return hr;
}
IFilterMapper2 *pFM2 = NULL;
hr = CoCreateInstance(CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
IID_IFilterMapper2, (void **)&pFM2);
if (SUCCEEDED(hr))
{
hr = pFM2->UnregisterFilter(&CLSID_VideoCompressorCategory,
g_wszName, CLSID_MyFilter);
pFM2->Release();
}
return hr;
}


extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID);
BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
{
return DllEntryPoint((HINSTANCE)(hModule), dwReason, lpReserved);
}

这里是使用过滤器的代码

#include <DShow.h>
#include "MyFilter.h"
#include <streams.h>


IPin *GetPin(IBaseFilter *pFilter, PIN_DIRECTION PinDir)
{
BOOL bFound = FALSE;
IEnumPins *pEnum;
IPin *pPin;

pFilter->EnumPins(&pEnum);
while(pEnum->Next(1, &pPin, 0) == S_OK)
{
PIN_DIRECTION PinDirThis;
pPin->QueryDirection(&PinDirThis);
if (bFound = (PinDir == PinDirThis))
break;
pPin->Release();
}
pEnum->Release();
return (bFound ? pPin : 0);
}


int CALLBACK WinMain(
_In_ HINSTANCE hInstance,
_In_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine,
_In_ int nCmdShow
)
{

CoInitialize(NULL);
IGraphBuilder* pGraph = NULL;
IMediaControl* pMediaControl = NULL;
IMediaEvent* pMediaEvent = NULL;

HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_ALL, IID_IFilterGraph, (void **) &pGraph);

if(hr < 0)
{
return -1;
}
IBaseFilter* pSource = NULL;
pGraph->QueryInterface(IID_IMediaControl, (void **) pMediaControl);
pGraph->QueryInterface(IID_IMediaEvent, (void **) pMediaEvent);
pGraph->AddSourceFilter(TEXT("C:\\TEMP\\video1.avi"), 0, &pSource);

IPin* pSourceOut = GetPin(pSource, PINDIR_OUTPUT);
IBaseFilter* pAVISplitter = NULL;
CoCreateInstance(CLSID_AviSplitter, NULL,
CLSCTX_INPROC_SERVER,
IID_IBaseFilter,
(void**)&pAVISplitter);

IPin* pAvIIn = GetPin(pAVISplitter, PINDIR_INPUT);

pGraph->AddFilter(pAVISplitter, L"Splitter");
pGraph->Connect(pSourceOut, pAvIIn);

IPin* pAVIOut = GetPin(pAVISplitter, PINDIR_OUTPUT);


MyFilter* myfilter;
hr = CoCreateInstance(CLSID_MyFilter, NULL, CLSCTX_INPROC_SERVER, IID_MyFilter, (void **)& myfilter);
if(hr < 0)
{
return -1;
}
IPin* myfilterIn = myfilter->GetPin(0);
IPin* myFilterOut = myfilter->GetPin(3);
pGraph->Connect(pAVIOut, myfilterIn);

pGraph->Render(myFilterOut);

CoUninitialize();


return 0;

}

简单调用基类:

STDMETHODIMP MyFilter::NonDelegatingQueryInterface(REFIID riid, void **ppv)
{

return CBaseFilter::NonDelegatingQueryInterface(riid, ppv);
}

另请注意,我可以在 graphedit 中导入我的过滤器

最佳答案

MyFilter::NonDelegatingQueryInterface is where you should look at

简单调用基类:

与 EzRGB24 示例进行比较,后者与您的示例类似,添加了自定义界面。您需要分别更新您的项目。

//
// NonDelegatingQueryInterface
//
// Reveals IIPEffect and ISpecifyPropertyPages
//
STDMETHODIMP CEZrgb24::NonDelegatingQueryInterface(REFIID riid, void **ppv)
{
CheckPointer(ppv,E_POINTER);

if (riid == IID_IIPEffect) {
return GetInterface((IIPEffect *) this, ppv);

} else if (riid == IID_ISpecifyPropertyPages) {
return GetInterface((ISpecifyPropertyPages *) this, ppv);

} else {
return CTransformFilter::NonDelegatingQueryInterface(riid, ppv);
}

}

关于c++ - 直接显示过滤器的 CoCreateInstance 返回 E_NOINTERFACE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22100058/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com