2

I have been able to implement a preview handler for most file types, except outlook msg files. How can I achieve this? The code doesnt seem to be able to open either in stream or file mode.

var
  ACLSID: String;
  AGUID: TGUID;
  ARect: TRect;
  FileInit: IInitializeWithFile;
  StreamInit : IInitializeWithStream;

begin
  FPreviewHandler := CreateComObject(AGUID) as IPreviewHandler;
  if (FPreviewHandler = nil) then
  begin
    MessageDlg('No preview handler found for this file format.', mtError, [mbOK], 0);
    Result := False;
    Exit;
  end;

  // First attempt opening in file mode, if fails, attempt stream mode.
  if FPreviewHandler.QueryInterface(IInitializeWithFile, FileInit) = 0 then
  begin
    FileInit.Initialize(StringToOleStr(FFileName), STGM_READ);
    FInStreamMode := False;
    FLoaded := True;
  end else
  if FPreviewHandler.QueryInterface(IInitializeWithStream, StreamInit) = 0 then
  begin
    try
      FFileStream := TFileStream.Create(FFileName, fmOpenRead);
    except on
      E: EFOpenError do
      begin
        MessageDlg(E.Message, mtError, [mbOK], 0);
        Result := False;
        Exit;
      end;
    end;
    FIStream := TStreamAdapter.Create(FFileStream, soOwned) as IStream;
    StreamInit.Initialize(FIStream, STGM_READ);
    FInStreamMode := True;
    FLoaded := True;
  end else
  begin // Cannot load file
    Result := False;
    FPreviewHandler.Unload;
    Exit;
  end;

  ARect := Rect(0, 0, AParentControl.Width, AParentControl.Height);
  Parent := AParentControl;
  Align := alClient;
  FPreviewHandler.SetWindow(Self.Handle, ARect);
  FPreviewHandler.SetRect(ARect);
  FPreviewHandler.DoPreview;
  FPreviewHandler.SetFocus;
dtb
  • 213,145
  • 36
  • 401
  • 431
Phillip Roux
  • 173
  • 2
  • 10
  • 1
    It doesn't look like you've *implemented* any preview handlers at all. It looks like you're trying to se the ones that are already there. Are you sure the object you've instantiated supports preview handlers? What class did you instantiate from that GUID? – Rob Kennedy Jun 22 '10 at 05:22

0 Answers0