2

I'm using IPersistFile in C# to load a file, before reading it as an IFilter:

IFilter filter = LoadIFilter (fileextension);
IPersistFile persistFile = (filter as IPersistFile);
if (persistFile != null) {
    persistFile.Load (fileName, 0);
    IFILTER_FLAGS flags;
    IFILTER_INIT iflags = IFILTER_INIT.FILTER_OWNED_VALUE_OK;
    if (filter.Init (iflags, 0, IntPtr.Zero, out flags) == IFilterReturnCode.S_OK) {
        return filter; // will be read using GetChunk/GetText
    }
}

This works fine.

However, I would like to load the file contents from memory instead of a disk path. Is that possible? The IPersistFile interface does not show any other way than providing a path string, so it seems neither a memory mapped file nor a byte array can be used.

mafu
  • 31,798
  • 42
  • 154
  • 247

1 Answers1

1

As a preleminary answer sketch: My research indicates that it might be possible to cast to IPersistStream instead of IPersistFile, which allows loading from an IStream and thus from a memory target.

mafu
  • 31,798
  • 42
  • 154
  • 247
  • Yes, all sane `IFilter` implementation should implement `IPersistStream` and you can just try to query `IPersistStream` and use it. – sharptooth May 29 '13 at 07:07
  • @sharptooth Thanks, I see. So an IFilter should implement as many IPersistX interfaces as possible to be usable in all situations. – mafu May 29 '13 at 08:23
  • Well, not really, the minimum seems to be `IFilter`, `IPersistFile` and `IPersistStream`. – sharptooth May 29 '13 at 09:09
  • Be aware, some iFilters ONLY support one of the IPersist* interfaces. Windows Search uses the IPersistStream interface on iFilters, but does not use IPersistFile. And ifilttst uses IPersistFile. Some manufacturers only implement one to limit their usability on purpose. – tdemay May 26 '16 at 18:13