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

Raoul raoulsam at yahoo.com
Sun Jun 13 20:04:35 EDT 2004


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



More information about the Python-list mailing list