467,223 Members | 1,400 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,223 developers. It's quick & easy.

Win32 COM

I don't know anything about COM beyond the fact that I can look in the
OLE/COM browser to maybe figure out the API that an object has that I
need to operate on. Usually this gets me by fine; I've written mostly
utilities for Developer Studio which work fine if a little slow, and a
bit of junk for some other bits of the MS Office suite. However, now
I'm a bit stuck.

I've got this object, and the documentation and sample code imply that
I can just call this method I need to call on it, and ding-dong. It's
for creating a "command" object to pass to the application, and it
works (or rather, is supposed to work) sorta like this:

operation = win32com.client.Dispatch('AppHelper.AppParameter')
operation.Command = 'A_Command_Name'
operation.SetParameter('param1', 'value')

However, I get an attribute error on the SetParameter call, which
indicates that it doesn't exist.

So, I look at the object browser, and sure enough it isn't there.
However, there is a 'Parameter' method. Oh wait, there are two.
There's one that takes the parameter name and (presumably) returns the
value, and there's another that takes the parameter name and the value
that it's set to.

Through fiddling with this thing in IPython, I found that I can do:

operation.Parameter('foo')

....which throws an exception, but once that's been run, I can do what
I set out to do:

operation.SetParameter('param1', 'value')

....and all is well.

Can anyone give me any tips as to what's going on here and what I
might be doing wrong? I have /not/ run the makepy.py or whatever it
is, since when I roll this out to the team I don't want to have to run
that on every machine before it'll work, but if that's what I need to
do, well, so be it. However, at this time I'm stumped as to what to
try except that I can have a dirty-feeling try/except bit to "enable"
that call...

thx,
-tom!
Nov 2 '06 #1
  • viewed: 1245
Share:
1 Reply
Tom Plunket wrote:
I don't know anything about COM beyond the fact that I can look in the
OLE/COM browser to maybe figure out the API that an object has that I
need to operate on.
I'm still not entirely sure what's going on, because there are some
methods and properties that are available before doing this, but
makepy was part of my solution.

What I wanted to avoid was explicitly going around and running makepy
N times on everyone's machine that might need to run this toolset.
What I discovered I could do was run makepy with a -i command-line
parameter, which would emit code that would kick the gencache to
implicitly run makepy if necessary. So, problem solved!

in my case:

: C:\Python24\Lib\site-packages\win32com\client>makepy -i
: NxNXMLHelper 1.0 Type Library
: {5E7B0F01-92C1-11D3-A5FB-00104B45886F}, lcid=0, major=1, minor=0
: >># Use these commands in Python code to auto generate .py support
: >>from win32com.client import gencache
: >>gencache.EnsureModule('{5E7B0F01-92C1-11D3-A5FB-00104B45886F}', 0, 1, 0)

Very handy!
-tom!
Nov 2 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by RL | last post: by
5 posts views Thread by Bryan Parkoff | last post: by
2 posts views Thread by Tony Johansson | last post: by
8 posts views Thread by Tony Johansson | last post: by
reply views Thread by =?Utf-8?B?Q29saXZpZXI=?= | last post: by
reply views Thread by Adict | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.