[python-win32] Python COM and IUnknown

David Nicolson davidnicolson1 at hotmail.com
Tue May 23 14:45:03 CEST 2006


Hi,

I have a win32com application that dispatches a COM object, using  
late or early binding and with events using win32com.client.WithEvents.

The application that is dispatched to sends an event when it is  
quitting, leaving time for the client to disconnect from the COM  
server. When this event is received, the del statement is run on both  
the COM and events object. The problem is that the reference count in  
Python of these objects, and the GatewayCount and InterfaceCount  
returned from pythoncom remain above 0.

After months of trial and error I sought out a solution leveraging  
ctypes. This email on the ctypes mailing list looked as if it would  
be possible to reduce the COM reference count, circumventing the  
connection between Python reference counts and COM reference counts.

http://sourceforge.net/mailarchive/message.php?msg_id=5094807

Since that email the ctypes.com module has been moved to a separate  
project, titled comtypes. The IUnknown object did not have a  
from_address attribute in the comtypes module though.

Any suggestions or help would be appreciated.

Thanks,
Dave




More information about the Python-win32 mailing list