Skip to main content

A python package implements interface IMessageFilter for COM

Project description

A python package implements interface IMessageFilter for COM.

The main purpose is to fix ‘Application is Busy’ and ‘Call was Rejected By Callee’ errors in a WINDOWS COM/COM+ client.

Here is a workaround

But it’s written by C#, this package offers both C and Python versions.


Install it:

pip install imessagefilter

Import CMessageFilter from imessagefilter

Call static method register at the beginning of automation

Call static method revoke at the end of work

Here it’s an example:

from comtypes.client import CreateObject
from imessagefilter import CMessageFilter

def iter_excel_sheets(filename):
    aobj = CreateObject('Excel.Application', dynamic=True)
    for sheet in aobj.ActiveWorkbook.Worksheets:
        print('Processing %s' % sheet.Name)


The interface IMessageFilter only works in single-threaded apartments, it will not be called in the multithreaded apartments.

Refer to

Build msgfilter.dll

By visual studio command line:

cl /LD msgfilter.c ole32.lib

By mingw32 in cygwin:

i686-pc-mingw32-gcc -shared -o msgfilter.dll msgfilter.c -lole32 -luuid

There are 2 export functions, they can be used in any c file.

Here it’s an exmaple:

#include <stdio.h>
#include <objbase.h>

extern void register_message_filter();
extern void revoke_message_filter();

int main(int argc, char* argv[])
  HRESULT ret;
  ret = CoInitializeEx(0, COINIT_APARTMENTTHREADED);

  // do something for automation


  return 0;

Change Logs


  • Search msgfilter.dll in the current path first


  • Fix no long description in package information


  • Fix typos

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for imessagefilter, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size (28.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page