COM and COM and Python and COM - comtest.py [0/1] 
Author Message
 COM and COM and Python and COM - comtest.py [0/1]

As I am not very fluent with COM/Python internals, I would like to ask if
the problem with the attached simple test program is:

a) a bug
        a1) in my test program
        a2) in python COM
b) a feature
        b1) temporary
        b2) not so temporary
c) abuse of COM and Python
d) some other

If you run the program, it prints two error messages; "ERROR IN 1" and
"ERROR IN 2".

comtst.use("OBJ3", "KEY") works OK, as do the lines above:

o1 = comtst.get("OBJ1")
print o1.Item("KEY")
...

So, in Python COM server it seems to possible to use only COM objects
whose reference has been stored inside the COM object.

I guess the problem is that the object type seems to be PyIDispatch. What
is the "correct" way to wrap it inside CDispatch, if that is what is
needed?

My environment is WinNT 4, Python 1.5.1 with COM extensions version 122,
and the "Scripting.Dictionary" is from MS Scripting DLL.

R:TAU



Fri, 04 May 2001 03:00:00 GMT  
 COM and COM and Python and COM - comtest.py [0/1]

Quote:

>As I am not very fluent with COM/Python internals, I would like to ask if
>the problem with the attached simple test program is:

>a) a bug
> a1) in my test program
> a2) in Python COM
>b) a feature
> b1) temporary
> b2) not so temporary
>c) abuse of COM and Python
>d) some other

>If you run the program, it prints two error messages; "ERROR IN 1" and
>"ERROR IN 2".

>comtst.use("OBJ3", "KEY") works OK, as do the lines above:

>o1 = comtst.get("OBJ1")
>print o1.Item("KEY")
>...

>So, in Python COM server it seems to possible to use only COM objects
>whose reference has been stored inside the COM object.

>I guess the problem is that the object type seems to be PyIDispatch. What
>is the "correct" way to wrap it inside CDispatch, if that is what is
>needed?

It is "a1" -- a bug in your program. I would also tend to call it a
"mis-feature" in Python COM(*).

What is happening is that Python COM receives an IDispatch interface pointer
via COM. It places that into a PyIDispatch instance and passes it to your
COM server. PyIDispatch is not a "Python-ish" interface. To call Item(),
you'd need to use GetIDsOfNames and Invoke(). The win32com.client stuff is
supposed to do that for you -- wrapping up the ugly IDispatch interface into
something pleasant.

So yes: you assumed correctly -- it should be wrapped into a CDispatch
(although you really shouldn't need to know about the CDispatch class). To
wrap it is quite easy:

 def set(self, name, obj):
  self.m_d[name] = win32com.client.Dispatch(obj)

In other words, win32com.client.Dispatch() understands that it should create
an object when you pass it a PROGID, and it also understands that it should
wrap a PyIDispatch object that is passed to it.

Note that get() will still function: Python COM "knows" about CDispatch and
will extract an IDispatch* properly to return via COM.

-g

(*) what should *really* happen is that Python COM would pass you a
CDispatch object so that you can work with the thing more easily. This is
slated for a future rework of the Python COM package (won't happen till next
year, so don't consider it "temporary"). Until then, servers need to wrap
incoming objects with convenience objects (if they so desire).

--
Greg Stein, http://www.lyra.org/



Fri, 04 May 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. how to register COM interface from python COM-server

2. Catch COM events generated by a Python COM server with Visual Basic

3. a simple C++ COM vs python COM

4. tgriggs@keyww.com <tgriggs@keyww.com>

5. Address Change, cameron@sna.dec.com to cameron@stl.dec.com

6. Retrocomputing Museum Progress Report (http://compilers.iecc.com/comparch/arti

7. Com 1 to Com 2

8. Changing Com 1 to Com 2

9. COM<->COM communication

 

 
Powered by phpBB® Forum Software