By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,908 Members | 2,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,908 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ra******@yahoo.com (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/pytho...pter/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
Jul 18 '05 #2

P: n/a
ti********@viacom-outdoor.co.uk (Tim Golden) wrote in message news:<83**************************@posting.google. com>...
ra******@yahoo.com (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/pytho...pter/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...
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.