Win32 COM

T

Tom Plunket

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!
 
T

Tom Plunket

Tom said:
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top