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 ...
Get Python Programming On Win32 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.