Skip to Main Content
Python Programming On Win32
book

Python Programming On Win32

by Andy Robinson, Mark Hammond
January 2000
Intermediate to advanced content levelIntermediate to advanced
672 pages
21h 46m
English
O'Reilly Media, Inc.
Content preview from Python Programming On Win32

The Final Sample

A final sample COM server demonstrates wrapping and unwrapping objects, how to use IDispatch objects when passed as parameters to COM functions, and also how to debug your COM servers. This example is contrived and does nothing useful other than demonstrate these concepts.

The sample exposes two COM objects, a Parent object and a Child object. The Parent object is registered with COM so VB code can use CreateObject to create it. The Child object isn’t registered and can be created only by calling the CreateChild() method on the Parent. The Child object has no methods, just a Name property.

The Parent object also has a method called KissChild(), that should be called with a Child object previously created by the parent. The KissChild() method demonstrates how to use the IDispatch passed to the method and also how to unwrap the IDispatch to obtain the underlying Python object.

Finally, the code has a number of print statements and a lack of error handling. We use the debugging techniques to see these print statements and also a Python exception raised:

# ContrivedServer.py # # A contrived sample Python server that demonstrates # wrapping, unwrapping, and passing IDispatch objects. # Import the utilities for wrapping and unwrapping. from win32com.server.util import wrap, unwrap import win32com.client # Although we are able to register our Parent object for debugging, # our Child object is not registered, so this won't work. To get # the debugging behavior for our wrapped ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Python Programming - Second Edition

Advanced Python Programming - Second Edition

Quan Nguyen

Publisher Resources

ISBN: 1565926218Supplemental ContentErrata Page