SHARE
TWEET

ifilter fix

a guest Dec 28th, 2016 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         internal static IFilter LoadAndInitIFilter(string fileName, string extension)
  2.         {
  3.             IFilter filter = LoadIFilter(extension);
  4.  
  5.             if (filter == null)
  6.                 return null;
  7.  
  8.             var iPersistStream = filter as IPersistStream;
  9.             if (iPersistStream != null)
  10.             {
  11.                 IFILTER_FLAGS flags;
  12.                 IFILTER_INIT iflags =
  13.                             IFILTER_INIT.CANON_HYPHENS |
  14.                             IFILTER_INIT.CANON_PARAGRAPHS |
  15.                             IFILTER_INIT.CANON_SPACES |
  16.                             IFILTER_INIT.APPLY_INDEX_ATTRIBUTES |
  17.                             IFILTER_INIT.HARD_LINE_BREAKS |
  18.                             IFILTER_INIT.FILTER_OWNED_VALUE_OK;
  19.  
  20.                 Stream fileStream = new System.IO.FileStream(fileName, FileMode.Open);
  21.                 StreamWrapper wrapper = new StreamWrapper(fileStream);
  22.                 iPersistStream.Load(wrapper);
  23.  
  24.                 if (filter.Init(iflags, 0, IntPtr.Zero, out flags) == IFilterReturnCode.S_OK)
  25.                     return filter;
  26.             }
  27.  
  28.             IPersistFile persistFile = (filter as IPersistFile);
  29.             if (persistFile != null)
  30.             {
  31.                 persistFile.Load(fileName, 0);
  32.                 IFILTER_FLAGS flags;
  33.                 IFILTER_INIT iflags =
  34.                             IFILTER_INIT.CANON_HYPHENS |
  35.                             IFILTER_INIT.CANON_PARAGRAPHS |
  36.                             IFILTER_INIT.CANON_SPACES |
  37.                             IFILTER_INIT.APPLY_INDEX_ATTRIBUTES |
  38.                             IFILTER_INIT.HARD_LINE_BREAKS |
  39.                             IFILTER_INIT.FILTER_OWNED_VALUE_OK;
  40.  
  41.                 if (filter.Init(iflags, 0, IntPtr.Zero, out flags) == IFilterReturnCode.S_OK)
  42.                     return filter;
  43.             }
  44.             //If we failed to retreive an IPersistFile interface or to initialize
  45.             //the filter, we release it and return null.
  46.             Marshal.ReleaseComObject(filter);
  47.             return null;
  48.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top