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

Discussion in 'Python' started by Raoul, Jun 14, 2004.

  1. Raoul

    Raoul Guest

    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

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

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

    import win32com.client

    vals = [1.2,1.4,1.5,3.4]

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

    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.
    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 =

    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

    Raoul, Jun 14, 2004
    1. Advertisements

  2. Raoul

    Tim Golden Guest

    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:

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

    Tim Golden, Jun 14, 2004
    1. Advertisements

  3. Raoul

    Raoul Guest

    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...
    Raoul, Jun 18, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.