Problem with using PythonWin and ActiveX COM Object

Alex Martelli aleaxit at yahoo.com
Wed Oct 4 10:02:27 EDT 2000


"Jeremy Howard" <jeremyh at flashcom.com> wrote in message
news:stkikpeusp7057 at corp.supernews.com...
> I've asked this before but never really got an answer. I'm working for a
> company that is using Siebel CRM software.  This software comes with COM
> objects for accessing their system from external applications.  Below is
the

I don't know the details of their interfaces, but I'll give it a
try based on what you post...

> VB code that works and the Python code that doesn't.  If anyone has a
> solution I'd really appreciate it.
>
> VB Code...
>
> Dim iErr as Integer
> Dim objSiebel as Object
>
> Set objSiebel = CreateObject("SiebelDataServer.ApplicationObject")
>
> objSiebel.LoadObjects("ConfigFile", iErr)
>
> <snip>
> the vb code above works fine with no problems.

It looks, specifically, as if iErr is passed by-reference; i.e., a
_reference_ to iErr is given to the LoadObjects method, which places
an error-code there (a strange thing to do in COM, although allowed;
normally, COM returns errors quite differently -- this looks like a
partial translation of some older C API...?).


> Python Code...
>
> import win32com.client
>
> iError = 0
>
> objSiebel = win32com.client.Dispatch("SiebelDataServer.ApplicationObject")
>
> objSiebel.LoadObjects("C:\\siebel\\bin\\psblprd.cfg", iError )
>
> <snip>
>
> the python code above throws the following error..
>
> Traceback (most recent call last):
>   File "C:\Python16\Pythonwin\pywin\framework\scriptutils.py", line 301,
in
> RunScript
>     exec codeObject in __main__.__dict__
>   File "C:\Development\Java\MX\testSiebel.py", line 7, in ?
>     objSiebel.LoadObjects("C:\\siebel\\bin\\psblprd.cfg", sError )
>   File "<COMObject SiebelDataServer.ApplicationObject>", line 2, in
> LoadObjects
> com_error: (-2147352571, 'Type mismatch.', None, 2)

Python's COM interface is no doubt passing iError by value (it always
does: no pass-by-reference in Python!) and I think this is what the
Siebel object is diagnosing as a type-error.

Try calling LoadObjects with just one argument, the path to the file;
it should then *RETURN* the iError value as its *RESULT*.  I.e.,
change the offending line to

    iError = objSiebel.LoadObject(r'c:\siebel\bin\psblprd.cfg')

(I'm using the r'' syntax to avoid having to double up the backslashes,
but that's another, purely-syntactic-sugar issue!).

This is how Python's COM support handles by-reference, output values: it
transforms them into results.  You may have to run makepy on the type
library of interest, and maybe use EnsureDispatch or equivalent to make
sure the genpy-supplied wrappers are used rather than purely dynamic
dispatching (it's a rather advisable thing anyway, in general), but I
think you might be able to get away without that.


Let us know if this works...!


Alex






More information about the Python-list mailing list