473,732 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 18 '05 #1
2 4883
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.a verager")
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
ti********@viac om-outdoor.co.uk (Tim Golden) wrote in message news:<83******* *************** ****@posting.go ogle.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.a verager")
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3411
by: Mike Margerum | last post by:
Hi I am trying to using a COM server I built in C++. I ran GenPy on my type library and I am able to instantiate objects from the server. What I can't figure out is how to create/use Record types from my COM server. I see them defined in my generated py file as a map RecordMap = { 'FormRecord': '{F6EBBC2A-E2D5-4921-A498-EA80AE851012}', 'ICD9Record': '{FA83723F-55F6-4D17-8309-A9D323A4FD01}', 'BrandRecord':...
0
4115
by: goermezer | last post by:
Hello, I have some problems to automate a CAD (computer aided design) Software called CATIA V5 from Dassault Systemes. CATIA V5 has a builtin VB-Editor like Word, Excel, … and registers itself as a COM-server. With VB one can automate everything in CATIA V5 with a lot of registered Object Libraries. A VB example:
0
2297
by: mb3242 | last post by:
Hello, I'm trying to use win32com to call a method in a COM object. I'm having a problem with Python choosing the wrong type when wrapping up lists into VARIANTs. The function I'm trying to call in C++ looks like this: HRESULT write( VARIANT * len, VARIANT * saData, VARIANT * result); Where saData contains a SafeArray of bytes and len is its length. The function returns any error information in result.
1
10540
by: David Nicolson | last post by:
Hi, I have been successfully using iTunes' COM interface with Python using either of the following lines successfully: iTunes = win32com.client.gencache.EnsureDispatch("iTunes.Application") iTunes = win32com.client.Dispatch("iTunes.Application") The only problem is that it will launch iTunes if it is not running by instantiating the object here. There are some reasons why I have
2
3299
by: ago | last post by:
I am trying to make the win32com HelloWorld server work with a VBA client but I get: Run-time error '-2147467259(80004005)': Automation error Unspecified error I googled for the error but the suggested solutions (commenting out _reg_class_spec_ and putting the server on the python path) do not seem to make any difference (to be precise, unless I comment out
2
3592
by: VolkerS | last post by:
Hallo, I need helping adding an existing Interface to an object I dispatched from a COM-server via win32com in Python. The Code for this in VisualBasic looks like that: Private Obj_1 As Obj1_LIB.Impl_1 Private mHelper As Object Private m_applJob As Object Private m_applModul As interface_Module //interface_Module is described in an IDL/TLB-File Private cont As Boolean
11
7726
by: Bill Davy | last post by:
I am trying to edit Contacts in Outlook. This is so I can transfer numbers from my address book which is an Excel spreadsheet to my mobile phone. I came across the following snippet of code which enabled me to the contacts at least list. I had to root around to discover CdoDefaultFolderContacts (though it was guessable; how could I enumerate win32com.client.constants?). I now want to work through the Contacts in Outlook patching in...
4
3613
by: sterling | last post by:
I'm curious as to why the difference between IDLE and pythonWin when using win32com. opening an excel file, i've attempted to grab the chart information out of the file. commands like co = ChartObjects(1) works in pythonWin but doesn't work in IDLE. however, on both co = chartobjects(1) works just fine.
2
10515
by: RyanN | last post by:
Greetings, I'm trying to get DispatchWithEvents() to work with HyperAccess (terminal program) without much success. I've done a bunch of searching and found some examples using IE: This works but doesn't handle the "Event Driven Functions": haObj = win32com.client.Dispatch(r"HAWin32") And so does this Internet Explorer Example:
0
8774
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.