You should be able to wrap a Person object - something like ob = win32com.server.util.wrap(Person(...)) - and just return that. You probably don't need the VARIANT dance, it should just work based on the type returned being a Dispatch wrapper.

HTH,

Mark

On 16/4/2023 7:27 am, Wuping Xin wrote:
I'd like to return another Python object,  using a method of a COM object defined using Python, something like below - is that doable? For in process COM object defined through Python,  is there any limitation about the types that can be returned from COM method?

class Person:
    _public_methods_ = ["Name"]

    def __init__(self, name, age):
        self.name = name
        self.age = age

    def Name(self, age = None):
        return self.name


# Define a Python class that will be registered as a COM object
class MyCOMObject:
    _public_methods_ = ["GetPerson"]

*def GetPerson(self, name, age):*
        p = Person(name, age)
my_variant = pywintypes.VARIANT(p, VARIANT.VT_DISPATCH)
        return my_variant

# Register the class as a COM object

win32com.server.register.UseCommandLine(MyCOMObject)

_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32
_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to