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
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;
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for imessagefilter-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f464bc2c9e84d909cf92a88d6c0dd3ea6eb6d676d89036fb60501712700000a |
|
MD5 | 0b449e20338f41245852a29dc6a0fa73 |
|
BLAKE2b-256 | 9046366c248d94b7a51a2052358af85ba45c0d2e962f77589b9a2b4e95cd4e4b |