function FindPinInterface(
const pFilter: IBaseFilter;
const iid: TGUID;
out ppUnk: IUnknown): HRESULT;
var
pF: IBaseFilter;
hr: HRESULT;
pEnum: IEnumPins;
pPin: IPin;
begin
if not Assigned(pFilter)
then
begin
Result := E_POINTER;
Exit;
end;
hr := E_FAIL;
pEnum :=
nil;
if Failed(pFilter.EnumPins(pEnum))
then
begin
Result := E_FAIL;
Exit;
end;
// Query every pin for the interface.
pPin :=
nil;
while (S_OK = pEnum.Next(1, pPin,
nil))
do
begin
hr := pPin.QueryInterface(iid, ppUnk);
if Succeeded(hr)
then
begin
break;
end;
end;
Result := hr;
end;
function FindInterfaceAnywhere(
const pGraph: IGraphBuilder;
const iid: TGUID;
out ppUnk: IUnknown): HRESULT;
var
pF: IBaseFilter;
hr: HRESULT;
pEnum: IEnumFilters;
begin
if not Assigned(pGraph)
then
begin
Result := E_POINTER;
Exit;
end;
hr := E_FAIL;
pEnum :=
nil;
if Failed(pGraph.EnumFilters(pEnum))
then
begin
Result := E_FAIL;
Exit;
end;
// Loop through every filter in the graph.
pF :=
nil;
while (S_OK = pEnum.Next(1, pF,
nil))
do
begin
hr := pF.QueryInterface(iid, ppUnk);
if Failed(hr)
then
begin
// The filter does not expose the interface, but maybe one of its pins does.
hr := FindPinInterface(pF, iid, ppUnk);
end;
if Succeeded(hr)
then
begin
break;
end;
end;
Result := hr;
end;
procedure Main();
var
hr: HRESULT;
GraphBuilder: IGraphBuilder;
UnknownInterface: IUnknown;
Overlay: IOverlay;
begin
hr := CoCreateInstance(CLSID_FilterGraph,
nil, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, GraphBuilder);
if Succeeded(hr)
then
begin
hr := FindInterfaceAnywhere(GraphBuilder, IOverlay, UnknownInterface);
if Succeeded(hr)
then
begin
hr := UnknownInterface.QueryInterface(IOverlay, Overlay);
if Succeeded(hr)
then
begin
// wuuup wuuup
end;
end;
end;
end;