473,372 Members | 1,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

questions about a C++ COM object accessed in Python via win32com

Hi

I am coding a C++ COM object which I want to access in Python. For that
I do have some detail questions and need help since I am not that familiar
with the documentation itself of Python and win32com yet.
1.
How do I know that...

import win32com.client

....was successful or not?
2.
In my COM object I do have the following C++ function:

STDMETHODIMP CMyTestObjekt::Connect()
{
if (m_boolReadyToConnect == false) {
return E_FAIL;
}
return S_OK;
}

How do I know in Python whether I got back a S_OK or an E_FAIL? Or is this
whole concept wrong and I should better make an additional return value like:

MyFunktion(......., [out, retval] BOOL *pVal); (declaration in the IDL)
3.
If I execute the following command...

MyObject = win32com.client.Dispatch("MyCOM.MySuperCOMObject")

....what is the return value from which I know whether it was successful?
Or what can be the ""content"" of "MyObject" afterwards?
4.
If I have a function in Python in which I call the (global) COM Object,
what "if" do I have to use to know whether the COM object already had
been allocated? I tried the following but that didn't work:

def foo():
if MyObject == None:
print "COM not there yet"
else:
print MyObject.Message
I'd really appreciate any help. Or even a hint where to look in the "original"
documentation. FYI: I do use Win2000 and ActiveState ActivePython 2.2 which
already includes win32com.

Bye,
Matthias "T.T.H." Grobe
Jul 18 '05 #1
3 2069
T.T.H. wrote:
Hi

I am coding a C++ COM object which I want to access in Python. For that
I do have some detail questions and need help since I am not that familiar
with the documentation itself of Python and win32com yet.
1.
How do I know that...

import win32com.client

...was successful or not?
If it fails, it raises an exception -- so, if you want to handle the
failure, you try this statement in the try clause of a try/except
statement. That is reasonably similar to C++'s exception (syntax
apart), so the concept shouldn't be too alien.

2.
In my COM object I do have the following C++ function:

STDMETHODIMP CMyTestObjekt::Connect()
{
if (m_boolReadyToConnect == false) {
return E_FAIL;
}
return S_OK;
}

How do I know in Python whether I got back a S_OK or an E_FAIL? Or is this
E_FAIL translates into an exception.
whole concept wrong and I should better make an additional return value
like:

MyFunktion(......., [out, retval] BOOL *pVal); (declaration in the IDL)
This would be much more COM-idiomatic, unless the failure IS an exceptional
event, something that SHOULD not happen in a well-functioning system and
probably the result of mis-configuration or hardware malfunctioning.

3.
If I execute the following command...

MyObject = win32com.client.Dispatch("MyCOM.MySuperCOMObject")

...what is the return value from which I know whether it was successful?
Guess...?-) Yep: if it's not successful it raises an exception!
Or what can be the ""content"" of "MyObject" afterwards?
If an exception wasn't raised, MyObject is an instance of some class
(you need not care about which one...) on which you can call methods
(which will be "proxied" to the actual C++-implemented COM object).

4.
If I have a function in Python in which I call the (global) COM Object,
what "if" do I have to use to know whether the COM object already had
been allocated? I tried the following but that didn't work:

def foo():
if MyObject == None:
print "COM not there yet"
else:
print MyObject.Message


If name "MyObject" has never been bound, trying to access it will...
I give you three guesses... *raise an exception*!

However, I _would_ suggest that in this case you set MyObject=None
at a global level and test as above (except, use "Myobject is None"
rather than ==) -- that is more idiomatic in Python.
Alex

Jul 18 '05 #2
> Alex Martelli <al***@aleax.it>

Praise you, Alex, that was the most precise answer I could have imagined!

Bye,
T.T.H.
Jul 18 '05 #3
> Alex Martelli <al***@aleax.it>

Praise you, Alex, that was the most precise answer I could have imagined!

Bye,
T.T.H.
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mikko Ohtamaa | last post by:
Hi, I am quite new to Python, PythonCom and COM generally. As a former Java programmer, I have found Python's flexible ability to access native Win32, especially COM, very comfortable. However,...
4
by: MK | last post by:
I'm working with IIS on W2K server. I'm trying to use module "wmi" in a CGI script but with no success. The following works: import cgitb; cgitb.enable() cgi.test() .... but the...
3
by: Paul | last post by:
Hi I'm trying to build a standalone COM exe server using Python 2.2 + Mark Hammond's windows extensions + Py2Exe. I've built the example linked on the Py2Exe homepage and get this error when...
3
by: Fernando Gabrieli | last post by:
I need to communicate with Outlook 2000 COM object using win32com in Python. I registered a new class and called win32com.server.register.UseCommandLine(OutlookAddin) using this for...
3
by: Paul Keating | last post by:
I have a very simple COM server written in Python that is trying to return a two-dimensional array 268 x 20. The values it contains are some small integers, some short (<29 character) Unicode...
1
by: Gijs Korremans | last post by:
Hi, I'm still figuring out how I can use the win32com for the use of a com object which I think is made in VB First I've created a file with MakePy Then I used the following code to init the...
1
by: Gijs Korremans | last post by:
> Does IPADDRESSSTRUCT appear anywhere in the makepy-generated module ? Specifically, there should be a RecordMap dict containing any defined Records and their GUID's. No it's not in the...
5
by: bg_ie | last post by:
Hi, I wish to write a Python wrapper for my C# COM object but am unsure where to start. I have a dll and a tlb file, and I can use this object in C via the following code - // ConsolApp.cpp :...
2
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.