[python-win32] Re: problems in returning parameters using a COM client

George Vestergom unifoam@total.net
Tue, 24 Dec 2002 13:26:34 -0500

Mark Hammond wrote:
> Try running makepy over the Corel object, or better, use
> win32com.client.gencache.EnsureDispatch() in place of
> win32com.client.Dispatch to create the object.
> >   File "<COMObject CorelDraw.automation.6>", line 2, in
> This implies your object is not using makepy - EnsureDispatch() should force
> that.  However, if upon doing that you still get the same error, with the
> COM object being printed as "<COMObject ...>", then corel sucks and you must
> jump some extra hoops.  These hoops will look something like:
> cd_mod = gencache.EnsureModule(...)
> cd = Dispatch("CorelDraw.Automation")
> print repr(cd) # Will print "<COMObject CorelDrawautomation.6>"
> cd = cd_mod.Application(cd)
> print repr(cd) # Will print "<win32com.genpy....>"
> cd should now work correctly.  Lotus notes has this same problem, so
> googling for "EnsureModule notes" is likely to find some good hits - but
> hopefully just switching to EnsureDispatch() will get everything working
> with byrefs.


Thanks for the tip. It WORKS!

Here's what I ended up with:

>>> from win32com.client import Dispatch, gencache
>>> cdm = gencache.EnsureModule('{C8E9D4E1-181F-11CE-B115-00C0F002D9E5}', 0, 6, 0))  
>>> d = Dispatch('CorelDraw.automation.6')
>>> cd = cdm.IDrawAutomate(d)
>>> print cd

Now when I draw a rectangle, I can get the current position using:
>>> cd.GetPosition()

without problem. All the other methods such as GetSize, GetOutline, etc.
which return various number of parameters work as well.

For those who are using (still!) CorelDraw 6 like myself, the entry
point is through the IDrawAutomate object. There is no Application
object for this version. CorelDraw versions 9 and up uses Microsoft's
Visual Basic for Applications and (I'm assuming) have an object model
similar to MS Office applications such as Excel, Word, etc.

Thanks to Don Dwiggins for his suggestions as well. 

Merry Christmas and best wishes for the New Year!

Yours truly,
George Vestergom