delphidirectshowdspack

Load directshow filter from file using DSPack


How can I load a DirectShow filter not registered by an .ax file in delphi 7 using DSPack? I found an example in C++, I do not know how to translate it into Delphi.


Solution

  • Here you go:

    function LoadFilter(const Fhandle: HMODULE; clis: TGUID): IBaseFilter; overload;
    Var
      DllGetClassObject: Function(Const clsid, IID: TGUID; Var Obj)
        : HRESULT; STDCALL;
      ClassF: IClassFactory;
    Begin
      result := nil;
      try
        If Fhandle = 0 Then
          exit;
        // NOTE: Fhandle is typically obtained as a result of LoadLibrary API
        //       call loading DLL hosting the DirectShow filter
        DllGetClassObject := GetProcAddress(Fhandle, 'DllGetClassObject');
        DllGetClassObject(clis, IClassFactory, ClassF);
        if assigned(ClassF) then
        begin
          if ClassF.CreateInstance(nil, IID_IBaseFilter, result) = ERROR_SUCCESS
          then
            exit;
        end;
      except
        exit;
      end;
    end;