[python-win32] win32com and extended error messages: IDL with [out, retval] long* error)

Sandy Walsh swalsh at impathnetworks.com
Mon Dec 1 15:52:01 CET 2008


Hi,

I have a C++ COM Server with an IDL entry of:

[
    object,
    uuid(D989CB9A-0013-4E1A-BFB6-98A7946BD255),
    dual,
    helpstring("IFoo Interface"),
    pointer_default(unique)
]
interface IFoo : IDispatch
{
    [ id(1), helpstring("method Connect")]
        HRESULT Connect([in] BSTR x, [in] short y, [in] BSTR z, [out, 
retval] long* error);
};

A call from Python to the C++ object works fine unless I return 
something other than S_OK for "error".

If I return my own HResult error code an exception gets thrown:

 try:       
            print "Trying to connect"
            self.assertEqual(0, self.control.Connect("10.0.0.0", "9999", 
""))
        except pythoncom.com_error, (hr, msg, exc, arg):
            hr = 0xFFFFFFFF + hr + 1
            print "The call failed with code %X: %s" % (hr, msg)
            if exc is None:
               print "There is no extended error information"
            else:
                wcode, source, text, helpFile, helpId, scode = exc
                if source:
                    print "Source: ", source
                if text:
                    print "Error: ", text
                if helpFile:
                    print "More info can be found in %s (id=%d)" % 
(helpFile, helpId)

The call failed with code 80020009: Exception occurred.
The source of the error is None
The error message is None
More info can be found in None (id=0)
Win32 exception occurred releasing IUnknown at 0x00e84c58

(where HR of 0x80020009 is DISP_E_EXCEPTION)

I've traced the python side of the code and how it appears to me is the 
"error" out variable is not being created in the argument list. So it 
seems that during the unmarshalling something dies horribly because it 
doesn't know how to deal with the error message.

The generated IFoo code looks like this:

    def Connect(self, x=defaultNamedNotOptArg, y=defaultNamedNotOptArg, 
z=defaultNamedNotOptArg):
        """method Connect"""
        return self._oleobj_.InvokeTypes(1, LCID, 1, (3, 0), ((8, 1), 
(2, 1), (8, 1)), x, y, z)

I'm not sending extended error messages on the C++ side, just setting 
this error code out variable. I can only assume that the exception is 
being generated in the MS Com libraries when it tries to marshal the 
error variable into a non-existent spot?

Is there something special I need to do to get win32com to handle this 
out variable properly?

Thanks in advance!

-Sandy




-------------- next part --------------
A non-text attachment was scrubbed...
Name: swalsh.vcf
Type: text/x-vcard
Size: 335 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-win32/attachments/20081201/98db8607/attachment.vcf>


More information about the python-win32 mailing list