From: cingram at my-dejanews.com (cingram at my-dejanews.com)
Date: Wed, 07 Apr 1999 20:51:00 GMT
Subject: COM Event Sinks and Connection Points in Python
Message-ID: <7eggfh$o0f$1@nnrp1.dejanews.com>
Content-Length: 2843
X-UID: 996                                                  

I am trying to use functionality from a DLL that requires me to create a COM
event sink so that it can call back with events.  I am trying to write this
event sink in Python.  However, when I try to create a SimpleConnection
object, it gives this exception: "Unable to open the access token of the
current thread".

In the source code for testPyComTest.py (which is the only thing I could find
that uses the SimpleConnection object) that comes with the win32all
distribution, the following three lines exist right above code that would test
the connection point functionality:

# AAARG - why do connection points fail?
print "Skipping connection points as we have a threading bug somewhere :-("
return

Now, this comment leads me to believe that Mark Hammond, the author of the
Python Win32 stuff, has the same problem.  Does anyone know how to get around
this problem?  Below is the sample code I am trying to use.

#---- test.py
import pythoncom

# The GUID was retrieved from the IDL file of an external DLL.
# Is there a better way to get these without hard coding?
IID_DEMEvents = pythoncom.MakeIID ("{7BAE0700-E7D5-11d0-9C22-0020AFF2B0F5}")

class MonitorEvents:
    """Event Sink for Test.DEM"""
    _reg_clsid_      = "{554A2C64-EC50-11D2-BD51-006097B6AF50}"
    _reg_desc_       = "PythonTest.MonitorEvents"
    _reg_progid_     = "PythonTest.MonitorEvents"
    _reg_class_spec_ = "test.MonitorEvents"
    _public_methods_ = ["onSubscribe"]
    _public_attrs_   = []
    _readonly_attrs_ = []
    _com_interfaces_ = [IID_DEMEvents]

    def onSubscribe (self):
        # Not implemented yet.
        pass

if __name__ == "__main__":
    import win32com.server.register
    import win32com.client
    import win32com.client.connect

    # Test.DEM is the ProgID of the event source.  (This is an
    # external DLL.)
    dem = win32com.client.Dispatch ("Test.DEM")

    # MonitorEvents is the Python class that implements the Event Sink.
    meobj = MonitorEvents()

    # The following line causes an exception.
    s = win32com.client.connect.SimpleConnection (dem, meobj, IID_DEMEvents)

  # Creating the SimpleConnection object fails with:  #  #Traceback
(innermost last):  #  File "T:\Playground\Python\Monitor\monitor.py", line
54, in ?  #  s = win32com.client.connect.SimpleConnection (dem, meobj,
IID_DEMEvents)	#  File "C:\Tools\Python\win32com\client\connect.py", line
10, in __init__  #  self.Connect(coInstance , eventInstance, eventCLSID)  # 
File "C:\Tools\Python\win32com\client\connect.py", line 27, in Connect	# 
self.cookie = self.cp.Advise(comEventInstance)	#pywintypes.com_error:
(-2147220990, 'Unable to open the access token of the current thread', None,
None)

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




