Skip to main content

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

https://docs.microsoft.com/en-us/previous-versions/ms228772(v=vs.140)

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

Usage

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):
    CMessageFilter.register()
    aobj = CreateObject('Excel.Application', dynamic=True)
    aobj.Workbooks.Open(filename)
    for sheet in aobj.ActiveWorkbook.Worksheets:
        print('Processing %s' % sheet.Name)
    CMessageFilter.revoke()

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);
  register_message_filter();

  // do something for automation

  revoke_message_filter();
  CoUninitialize();

  return 0;
}

Change Logs

0.2.1

  • Search msgfilter.dll in the current path first

0.1.3

  • Fix no long description in package information

0.1.2

  • Fix typos

Metadata

Release files for imessagefilter 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for imessagefilter 0.2.1
File Size Uploaded
imessagefilter-0.2.1.zip 28.2 kB Details

Release files / imessagefilter-0.2.1.zip

Download URL imessagefilter-0.2.1.zip
Size 28.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e4b3f51de48f3d08fab4f2e6cfcd21fdaea294abbc2b171084d1c5965961f52d
BLAKE2b-256 checksum
How to use checksums
14e6849ff1835ecd5d8f49e16060acdd013cdb898c2e6b14e4201c146fc4eff0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.9.1 pkginfo/1.4.1 requests/2.8.1 setuptools/2.1 requests-toolbelt/0.8.0 tqdm/4.15.0 CPython/3.4.2

Release history Release notifications | RSS feed

This release

0.2.1 This release

1 release file

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page