Implementing IPersistStorage using PythonCOM

Mark Hammond MarkH at ActiveState.com
Fri Dec 8 01:25:23 EST 2000


Edward Blakes wrote:

> CATID_PerspectiveAttributeTypeServer = pythoncom.MakeIID("{a guid}")
> CLSID_PythonSample = pythoncom.MakeIID("{a guid}")

This is probably a problem - it means a new GUID will be created each 
time it is run - definitely not what you want.  Paste generated GUIDs 
directly into the code.

Also - you _really_ should get my book ;-)  The discussion on debugging 
is what you need the most.

Adding this:

     import win32com.server.dispatcher
     useDispatcher = win32com.server.dispatcher.DefaultDebugDispatcher

Then changing your 2 "wrap" calls to:

     aServer = 
win32com.server.util.wrap(origObj,pythoncom.IID_IPersistStorage, 
useDispatcher=useDispatcher)

     # Test persistence
     aLockBytes = 
win32com.server.util.wrap(LockBytes(),pythoncom.IID_ILockBytes,useDispatcher=useDispatcher)

(note the new param - set "useDispatcher=None" when you are no longer 
debugging.

Then running you code results in the following to the "Trace collector":

in _InvokeEx_ with SetSize 0 1 (0,) None None
Traceback (most recent call last):
   File "f:\src\pythonex\com\win32com\server\dispatcher.py", line 58, in 
_InvokeEx_
     return self.policy._InvokeEx_(dispid, lcid, wFlags, args, kwargs, 
serviceProvider)
   File "f:\src\pythonex\com\win32com\server\policy.py", line 314, in 
_InvokeEx_
     return self._invokeex_(dispid, lcid, wFlags, args, kwargs, 
serviceProvider)
   File "f:\src\pythonex\com\win32com\server\policy.py", line 502, in 
_invokeex_
     return apply(func, args)
   File "F:\temp\delme.py", line 78, in SetSize
     return S_OK
NameError: name 'S_OK' is not defined


Which should give you a good indication of your problem!

Mark.




More information about the Python-list mailing list