Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old September 21st, 2003, 03:18 PM
T.T.H. T.T.H. is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 1 T.T.H. User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
question on C++ COM object accessed by 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...
Code:
import win32com.client
was successful or not?

2.
In my COM object I do have the following C++ function:
Code:
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:
Code:
Funktion(......., [out, retval] BOOL *pVal)


3.
If I execute the following command...
Code:
MyObject = win32com.client.Dispatch("MyCOM.MySuperCOMObject")
...what is the return value from which I know whether it was succesful? 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:
Code:
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 ActiveState ActivePython 2.2 which already includes win32com.

Bye,
Matthias "T.T.H." Grobe

Reply With Quote
  #2  
Old September 22nd, 2003, 09:16 AM
cvchen cvchen is offline
Hi, I'm Calvin
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: LosAngeles, SanDiego, Houston
Posts: 50 cvchen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 7 sec
Reputation Power: 5
what's up TTH... i don't know what COM objects are, and I'm really shaky on C++ (i hate it, actually)... i'll suggest what I think, but there are probably better ways that i'm unaware of. at least, I think I can help you with the first question for sure.

(1)
to know if your import stmt went through ok, just use dir().

ie:
--------------------------------------
import cgi

if 'cgi' in dir():
print "yep, it's there"
--------------------------------------

OR, you could just try to use a function or call an object of the module you imported inside of a 'try' block, with an 'except' block right after it in case the import stmt didn't go through. it wasn't imported correctly, your 'except' code will execute, because you'll get a NameError. of course, the thing with this second way is that you'll have to be absolutely certain that the object/function that you call from that module in your try block exists in the module you want to import, and that you're using it correctly.

(2)
do you know before hand if E_FAIL has a constant value? the way you have it used in the code, it seems like E_FAIL should be readily distinguishable from S_OK, but I could be totally wrong. I don't know what the contexts of either are, nor what kind of variable, etc etc... if my assumptions are correct (time has taught me the chances are slim). alternatively, you could return an array of length 2 with the first index indication true or false (false would be E_FAIL, I guess), and the second index being the value of E_FAIL or S_OK, correspondingly. that way, you can just check the first index of the returned array in python.

(3) & (4)
sorry, can't help ya there i don't know enough about the flow or context of your code to be able to suggest anything that'd be useful.

hope i've been at least somewhat helpful. have a good day.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > question on C++ COM object accessed by Python via win32com


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway