I created a new issue (with sample Delphi project to replicate the issue, including the Python source file where the COM server is defined): https://github.com/mhammond/pywin32/issues/2043
And I submit a PR: https://github.com/mhammond/pywin32/pull/2044 Thank you. Wuping ------ Original Message ------ From "Wuping Xin" <wup...@caliper.com<mailto:wup...@caliper.com>> To "Mark Hammond" <mhamm...@skippinet.com.au<mailto:mhamm...@skippinet.com.au>> Cc "Python-win32@python.org<mailto:Python-win32@python.org>" <Python-win32@python.org<mailto:Python-win32@python.org>> Date 4/17/2023 8:42:14 AM Subject Re[2]: win32com, server/policy.py bug? policy.py Line 639 Thanks. I'll submit a PR. When calling from a Delphi COM client (using OleVariant ), arg[0] will be set by Delphi a value of 0x8002000C, when the target Python method has NO argument (i.e., taking only "self"). This makes args non-empty. When calling from a C++ MFC/COM client, arg[0] will be set a value of "None", when the target Python method has NO argument (i.e., talking only "self"). This makes args non-empty. The following code would be a "protection" for parameterless Python method. import inspect if len(inspect.getfullargspec(func).args) == 1: return func() else: return func(*args) Wuping ------ Original Message ------ From "Mark Hammond" <mhamm...@skippinet.com.au<mailto:mhamm...@skippinet.com.au>> To "Wuping Xin" <wup...@caliper.com<mailto:wup...@caliper.com>> Cc "Python-win32@python.org<mailto:Python-win32@python.org>" <Python-win32@python.org<mailto:Python-win32@python.org>> Date 4/17/2023 8:14:31 AM Subject Re: win32com, server/policy.py bug? policy.py Line 639 WARNING EXTERNAL EMAIL On 16/4/2023 11:48 pm, Wuping Xin wrote: A better fix is to change Line 639 of win32com/server/policy.py to the following: import inspect if len(inspect.getfullargspec(func).args) == 1: return func() else: return func(*args) Then we can make VBA, Delphi, C++ .... all clients happy. Agree? Should I submit a pull request? I'm not sure ATM - I'd be quite surprised if there was a bug in COM functions with no args, so it may be more subtle than that. But you should certainly get either a PR or issue on github for this, ideally with a complete repro. It might be quite some time (ie, many weeks) before I can look at this in more detail. Thanks, Mark Wuping ------ Original Message ------ From "Wuping Xin" <wup...@caliper.com<mailto:wup...@caliper.com>> To "Mark Hammond" <mhamm...@skippinet.com.au<mailto:mhamm...@skippinet.com.au>> Cc "Python-win32@python.org<mailto:Python-win32@python.org>" <Python-win32@python.org<mailto:Python-win32@python.org>> Date 4/16/2023 9:28:48 AM Subject win32com, server/policy.py bug? policy.py Line 639 For the following code, the method "GetPerson" has no explicit argument (except self). class MyCOMObject: _public_methods_ = ["GetPerson"] #_reg_clsid_ = '{44ee76c7-1290-4ea6-8189-00d5d7cd712a}' #_reg_desc_ = "My COM server" #_reg_progid_ = "MyCOMObject" def get_person(self): person = Person("haha", 45) wrapped = win32com.server.util.wrap(person, useDispatcher = my_dispatcher) return wrapped When calling from VBA, like below , it works fine. Set o = CreateObject("MyCOMObject") Set p = o.get_person() However, when calling from C++, or Delphi, the following error will be thrown: "TypeError: MyCOMObject.get_person() takes 1 positional argument but 2 were given" Delphi code: procedure TForm1.Button1Click(Sender: TObject); var o: OleVariant; p: OleVariant; begin o := CreateOleObject('MyCOMObject'); p := o.get_person(); // error will be thrown s := p.name; age := p.age; ShowMessage(s); end; The fix is to change Line 639 of policy.py to the following: if len(args) == 1 and (args[0] == -2147352572 or args[0] == None): return func() else: return func(*args)
_______________________________________________ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32