<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>You should be able to wrap a Person object - something like <font
        face="monospace">ob = win32com.server.util.wrap(Person(...))</font>
      - 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.</p>
    <p>HTH,</p>
    <p>Mark<br>
    </p>
    <div class="moz-cite-prefix">On 16/4/2023 7:27 am, Wuping Xin wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:embf00a808-8dfe-4c04-865c-8d787bf64144@34d99c31.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <style id="css_styles" type="text/css">blockquote.cite { margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc }blockquote.cite2 {margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc; margin-top: 3px; padding-top: 0px; }a img { border: 0px; }li[style='text-align: center;'], li[style='text-align: center; '], li[style='text-align: right;'], li[style='text-align: right; '] {  list-style-position: inside;}body { font-family: 'Segoe UI'; font-size: 12pt; }.quote { margin-left: 1em; margin-right: 1em; border-left: 5px #ebebeb solid; padding-left: 0.3em; }</style>
      <div>I'd like to return another Python object,  using a method of
        a COM object defined using Python, something like below - is
        that doable?</div>
      <div>For in process COM object defined through Python,  is there
        any limitation about the types that can be returned from COM
        method?</div>
      <div><br>
      </div>
      <div><span>class Person:</span></div>
      <div>    _public_methods_ = ["Name"]</div>
      <div><br>
      </div>
      <div>    def __init__(self, name, age):</div>
      <div>        self.name = name</div>
      <div>        self.age = age</div>
      <div><br>
      </div>
      <div>    def Name(self, age = None):</div>
      <div>        return self.name</div>
      <div><br>
      </div>
      <div><br>
      </div>
      <div># Define a Python class that will be registered as a COM object</div>
      <div>class MyCOMObject:</div>
      <div>    _public_methods_ = ["GetPerson"]</div>
      <div><br>
      </div>
      <div>    <b>def GetPerson(self, name, age):</b></div>
      <div>        p = Person(name, age)</div>
      <div>       
        my_variant = pywintypes.VARIANT(p, VARIANT.VT_DISPATCH)</div>
      <div>        return my_variant</div>
      <div><br>
      </div>
      <div># Register the class as a COM object</div>
      <div><br>
      </div>
      <div>win32com.server.register.UseCommandLine(MyCOMObject)</div>
      <div id="xe20a224af7c7428">
        <blockquote type="cite" class="cite2">
        </blockquote>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
python-win32 mailing list
<a class="moz-txt-link-abbreviated" href="mailto:python-win32@python.org">python-win32@python.org</a>
<a class="moz-txt-link-freetext" href="https://mail.python.org/mailman/listinfo/python-win32">https://mail.python.org/mailman/listinfo/python-win32</a>
</pre>
    </blockquote>
  </body>
</html>