win32com.client passing a list of values to a C++ COM object.

R

Raoul

I wrote a COM server object in C++ a few months ago. I can use it from
Visual Basic, Visual C++, S-Plus and a number of other scripting
environments.

What I can't do is use it with my FAVOURITE scripting language,
Python.

I have tried everything by I'm going crazy here. Here is what I
have...

import win32com.client

vals = [1.2,1.4,1.5,3.4]

seg = win32com.client.Dispatch("CN.averager")
seg.learnAndRun(vals)

This code doesn't work. The first thing that run does is unpack the
data passed in...

STDMETHODIMP Csegmenter::learnAndRun(VARIANT y, VARIANT *segmented)
{
double *y_array = 0; _n_elements = 0;
_n_elements = unpack(y,&y_array);
assert((y_array) && (_n_elements));

and so on...

my unpack looks like this...

//Copy the variant array into a double array.
int
Csegmenter::unpack(VARIANT v, double **y)
{
HRESULT hr = S_OK;

int n_elements = 0;
int i = 0;

*y = 0;

if (v.vt & VT_ARRAY) {

in fact, from running it in the debugger, the code craps out on the
test v.vt & VT_ARRAY it doesn't return 1 like it should.

Debugging in a watch window reveals that v.vt = 8204 and VT_ARRAY =
8192

In fact, the watch window shows v = {???}.

The IDL for those of you who care... is ...

[id(32), helpstring("method learnAndRun")] HRESULT learnAndRun([in]
VARIANT y_array, [out,retval] VARIANT* segmented);


which is fairly typical.

THIS WORKS IN VISUAL BASIC, and from S-Plus.

Can anyone help me here? What is going wrong? I need to pass in an
array of doubles to the beast. I've even tried converting my vals to
an array but that didn't work either.

Does anyone have an example of how this is done from Python using
win32com.client?

R-S
 
T

Tim Golden

(e-mail address removed) (Raoul):
> I wrote a COM server object in C++ a few months ago. I can use it from
> Visual Basic, Visual C++, S-Plus and a number of other scripting
> environments.
>
> What I can't do is use it with my FAVOURITE scripting language,
> Python.
> import win32com.client
>
> vals = [1.2,1.4,1.5,3.4]
>
> seg = win32com.client.Dispatch("CN.averager")
> seg.learnAndRun(vals)

OK. I'm absolutely no expert here, but I understood that
pywin32 automatically converted an arbitrary Python sequence
to an array of VARIANTS. If you haven't already, have a look
at this chapter of Hammond & Robinson's Python Win32 book:

http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html

Also, try posting to the python-win32 list, in the hope
that someone more knowledgeable than I see your post:

http://mail.python.org/mailman/listinfo/python-win32

TJG
 
R

Raoul

(e-mail address removed) (Raoul):
I wrote a COM server object in C++ a few months ago. I can use it from
Visual Basic, Visual C++, S-Plus and a number of other scripting
environments.

What I can't do is use it with my FAVOURITE scripting language,
Python.
import win32com.client

vals = [1.2,1.4,1.5,3.4]

seg = win32com.client.Dispatch("CN.averager")
seg.learnAndRun(vals)

OK. I'm absolutely no expert here, but I understood that
pywin32 automatically converted an arbitrary Python sequence
to an array of VARIANTS. If you haven't already, have a look
at this chapter of Hammond & Robinson's Python Win32 book:

http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html

Also, try posting to the python-win32 list, in the hope
that someone more knowledgeable than I see your post:

http://mail.python.org/mailman/listinfo/python-win32

TJG

I found it. It was a subtle bug in my COM class. Basically my code
expected row major layouts of lists and python did it's in column
major form...
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top