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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Raoul

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

    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.a verager")
    seg.learnAndRun (vals)

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

    STDMETHODIMP Csegmenter::lea rnAndRun(VARIAN T y, VARIANT *segmented)
    {
    double *y_array = 0; _n_elements = 0;
    _n_elements = unpack(y,&y_arr ay);
    assert((y_array ) && (_n_elements));

    and so on...

    my unpack looks like this...

    //Copy the variant array into a double array.
    int
    Csegmenter::unp ack(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("met hod 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
  • Tim Golden

    #2
    Re: win32com.client passing a list of values to a C++ COM object.

    raoulsam@yahoo. com (Raoul):[color=blue]
    > 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.a verager")
    > seg.learnAndRun (vals)[/color]

    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:



    TJG

    Comment

    • Raoul

      #3
      Re: win32com.client passing a list of values to a C++ COM object.

      tim.golden@viac om-outdoor.co.uk (Tim Golden) wrote in message news:<8360efcd. 0406140009.3605 21f5@posting.go ogle.com>...[color=blue]
      > raoulsam@yahoo. com (Raoul):[color=green]
      > > 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.a verager")
      > > seg.learnAndRun (vals)[/color]
      >
      > 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[/color]

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

      Comment

      Working...