[python-win32] COM: Parameterless functions seen as properties

Obendorf, Keston keston.obendorf at intel.com
Tue Sep 16 00:19:01 CEST 2008


I'm doing COM development in both Python and C#. Things are working
well, but I'm running into an issue where trying to get parameterless
function returns the return value of that function, which Python then
tries to call, causing an error.

 

 

The C# class is an implementation of an IDL-defined interface.

 

//IDL 

interface IService : IDispatch

{

      [id(101)] HRESULT foo([out, retval] BSTR * pstr);

}

 

//C#

[ComImport]

[Guid("/*GUID of IService*/")]

interface IService{}

 

 

[ComVisible(true)]

[ProgId("bar")]

[Guid("Valid GUID")]

public class bar : IService

{

    public bar(){}

 

    public string foo()

    {

        return "foo"; 

    }

}

 

Now, getting a Dispatch of "bar" in Python is where the issue lies.

 

from win32com.client import Dispatch

bar = Dispatch("bar")

str = bar.foo()

 

>>TypeError: 'unicode' object is not callable

 

This is only a problem with the C# class. If the interface is
implemented in Pythong, the above code will work.

 

Now, this issue can be fixed by adding in _FlagAsMethod before calling
bar.foo()

 

bar._FlagAsMethod("foo")

 

I really don't want to have to do that every time I try to call a
parameterless method of a C# COM-object from Python. That's a huge
headache, especially because I am trying to keep the language any one
component is written in a non-issue. 

 

I've started to dive into the source code of dynamic.py and other Client
modules to try and figure out how I can make this distinction at
Dispatch-time, but it's rough going understanding everything that's
going on in there. Does anyone have any pointers or a straight up
solution to this problem? 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20080915/62f9931d/attachment.htm>


More information about the python-win32 mailing list