makepy support for versioning

Jim Kerr jim_kerr at agilent.com
Mon Jun 7 23:59:54 CEST 2004


Does makepy always respect versioning of interfaces? It appears as
though makepy correctly handles versioning of objects you obtain
directly, but not for objects you get via a function call.

  Here's a simple example to illustrate the point. I created the
C++-based server for this example by pilfering some code in Andrew
Troelsen's book on COM and ATL.

       car = Dispatch("ScriptibleCoCar.DualCoCar")
       person = Dispatch("ScriptibleCoCar.Person")  # a Person object
       carOwner = car.Person                        # also a Person
object

  Both the Car and the Person classes have two versions, and makepy
handles this correctly:

       >>> car
       <win32com.gen_py.ScriptibleCoCar 1.0 Type Library.IDualCoCar2
instance at 0x17800328>
       >>> person
       <win32com.gen_py.ScriptibleCoCar 1.0 Type Library.IPerson2
instance at 0x17800368>

(Notice the suffix 2 in both cases). OTOH, the Person object obtained
via car.Person is a version 1 thingie:

       >>> carOwner
       <win32com.gen_py.ScriptibleCoCar 1.0 Type Library.IPerson
instance at 0x14968112>

  If I try to use QueryInterface to get a reference to a version 2
object, it fails:

      >>> IID_IPerson2 = "{38332D31-6631-48E9-B62E-449864003395}"
      >>> carOwner._oleobj_.QueryInterface(IID_IPerson2)
      Traceback (most recent call last):
        File "<interactive input>", line 1, in ?
      TypeError: There is no interface object registered that supports
this IID

  Late binding works fine, however:

       >>> import win32com.client.dynamic
       >>> dcar = win32com.client.dynamic.Dispatch("ScriptibleCoCar.DualCoCar")
       >>> dperson = dcar.Person
       >>> dperson.Name, dperson.ID, dperson.Address  # Address is new
in version 2
       (u'Phony', 123, u'00 Anywhere Place')

  I'm kinda stuck here. I could live with using late binding, but the
interface I need to use has a lot of properties with parameters, and
makepy seems like the easiest way to deal with those. So my questions
are:
  1) Is there a way around this issue with makepy?
  2) If not, is there a way to set the values of properties with
parameters using late binding?

Thanks for the help!

Jim



More information about the Python-list mailing list