Using IFilter in C# by bypassing COM

Posted on March 12th, 2006.

I’ve been using IFilters in a C# application I’m working on, and it hasn’t been fun at all. There are all kinds of problems with COM threading and then there are some malfunctioning filter implementations.

Well, I decided one day to get to the bottom of these problems and finally created my own implementation of the LoadIFilter function.
The LoadIFilter function is used to find a filter implementation for a certain file. My implementation does what LoadIFilter does (and a bit more), but it does not involve COM in the process and avoids the threading problems mentioned above. Until now, it hasn’t introduced new problems..

Anyway, I packaged all that information (and source code) in an article and posted it to Code Project. You can find it here.  It has some nice information on how to dynamically load a dll and call a function pointer using GetProcAddress (which was not possible before .Net 2.0).

Hope you’ll find it useful.

UPDATE: The article moved to it’s permanent location after being edited. Link updated.

Technorati: , , ,

Make a Comment

Make A Comment: ( 6 so far )

blockquote and a tags work here.

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-Spam Image

6 Responses to “Using IFilter in C# by bypassing COM”

RSS Feed for Eyal’s Posts Comments RSS Feed

re: Visio 2003 IFilter and MTA…

Hey Eyal,

First, thanks for the code. We are testing your code in our site and are getting:
System.Runtime.InteropServices.COMException (0×80030050): already exists. (Exception from HRESULT: 0×80030050 (STG_E_FILEALREADYEXISTS))
at System.Runtime.InteropServices.ComTypes.IPersistFile.Load(String pszFileName, Int32 dwMode)
at EPocalipse.IFilter.FilterLoader.LoadAndInitIFilter(String fileName, String extension)
at EPocalipse.IFilter.FilterReader..ctor(String fileName)

Which is strange as you say there are no COM objects used.

ANy help will be appreciated.

Alon

Alon
January 3rd, 2008

The library bypasses the COM infrastructure used to load and create the COM object, but since the interfaces are COM based the errors you see are still COM errors.
The error you get usually happens when trying to open a file which is already open.

Eyal Post
January 8th, 2008

chalom Eyal
how can I program in C# or Java a global image filter .
I mean like Ifilter for all the system.
If I want to see any image or video or Flash coming to the screen according the built filter (GUID or any image filter built in C# or Java.
Toda
Zeev

zeev
May 11th, 2008

Hi,
First off, thanks for posting this example. I’m trying to use your posted library to scan a collection of documents. Everything works fine for the first file in the collection, but then on the second file i get an error “already exists. (Exception from HRESULT: 0×80030050 (STG_E_FILEALREADYEXISTS))” do you have any pointers on how to get around this? Thanks! Allan

Allan
June 10th, 2008

Hi Eyal,
Thanks for posting the code!
I’m trying to use your IFilter to extract text from different file types. It work good on word and text. I’m having some problems with the excel files. The text that I receive has the strings in different order. First I receive the text and then the numbers…sounds strange but…And with other implementation of IFilter I get the same thing.
With .csv files I get i get the error: “already exists. (Exception from HRESULT: 0×80030050 (STG_E_FILEALREADYEXISTS))”.
Any help is appreciated.
Thank you!
Doru

Doru
June 12th, 2008

Where's The Comment Form?

eXTReMe Tracker