使用Win32COM失败的COM对象的调用方法,但ComTypes成功
我有一个com库(smiseventhandler),我想使用Win32COM进行连接,该库会导出2类(Imgevents和Smisevents)。当我使用suemuredisPatch创建一个类的实例(“ smiseventhandler.imgevents”)
我获得了带有正确的uuid和接口等的对象 似乎都
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Public\Miniconda3\envs\hq_clin1\lib\site-packages\win32com\gen_py\2F06A879-D4E9-482E-AC01-E2B14A961C45x0x3x0\IDualImgEventTrigger.py", line 46, in ImageCreated
return self._oleobj_.InvokeTypes(1610809349, LCID, 1, (24, 0), ((8, 1), (8, 1), (8, 1), (3, 1), (8, 1), (17, 1), (8, 1)),PatientId
pywintypes.com_error: (-2147352573, 'Member not found.', None, None)
还好
>>> ehw2.Status(1, "success")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Public\Miniconda3\envs\hq_clin1\lib\site-packages\win32com\gen_py\2F06A879-D4E9-482E-AC01-E2B14A961C45x0x3x0\IDualImgEventTrigger.py", line 67, in Status
return self._ApplyTypes_(1610809344, 1, (24, 32), ((3, 1), (8, 1), (8, 49)), 'Status', None,Status
File "C:\Users\Public\Miniconda3\envs\hq_clin1\lib\site-packages\win32com\client\__init__.py", line 572, in _ApplyTypes_
self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args),
pywintypes.com_error: (-2147352562, 'Invalid number of parameters.', None, None)
,一切 在第二类(SmiseVents)上定义,但具有不同的签名。该二等班的实例在没有问题的情况下正常工作。
如果我以comtypes运行等效的代码,那么该方法调用按预期成功,
>>>obj = comtypes.client.CreateObject("SMISEventHandler.ImgEvents")
>>>obj.Status(1, "success")
0
库在从VB6访问时也可以正常工作。这表明COM库本身正常工作,并且故障在于Win32COM。这似乎与Stackoverflow的以下问题有关(除了使用ComTypes以外):“找不到成员。” 在实践中,使用win32com的错误
对我来说不是一个很好的解决方案,因为我需要win32com的跨线程编组能力,所以我非常热衷于找到解决这个问题的解决方案,但是无法尝试 - 尝试 - 尝试 -如果有人可以提出一些方法来更好地了解正在发生的事情,我一定会尝试的。
Python:3.9.12 Pywin32:303
I have a COM library (SMISEventHandler) with which I would like to interface using win32com, which exports 2 classes (ImgEvents and SMISEvents). When I create an instance of one of the classes using EnsureDispatch("SMISEventHandler.ImgEvents")
I get an object with the correct UUIDs and interface etc., the typelib is correctly passed to give the gencache interface files, and everything seems ok, but when I try to call some of the methods of the interface I get errors like:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Public\Miniconda3\envs\hq_clin1\lib\site-packages\win32com\gen_py\2F06A879-D4E9-482E-AC01-E2B14A961C45x0x3x0\IDualImgEventTrigger.py", line 46, in ImageCreated
return self._oleobj_.InvokeTypes(1610809349, LCID, 1, (24, 0), ((8, 1), (8, 1), (8, 1), (3, 1), (8, 1), (17, 1), (8, 1)),PatientId
pywintypes.com_error: (-2147352573, 'Member not found.', None, None)
or in some cases:
>>> ehw2.Status(1, "success")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Public\Miniconda3\envs\hq_clin1\lib\site-packages\win32com\gen_py\2F06A879-D4E9-482E-AC01-E2B14A961C45x0x3x0\IDualImgEventTrigger.py", line 67, in Status
return self._ApplyTypes_(1610809344, 1, (24, 32), ((3, 1), (8, 1), (8, 49)), 'Status', None,Status
File "C:\Users\Public\Miniconda3\envs\hq_clin1\lib\site-packages\win32com\client\__init__.py", line 572, in _ApplyTypes_
self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args),
pywintypes.com_error: (-2147352562, 'Invalid number of parameters.', None, None)
Interestingly, it seems that the methods where we see "Invalid number of parameters" correspond to the methods which are defined on the second class (SMISEvents), but which have a different signature. Instances of that second class work correctly with no issues.
If I run the equivalent code in comtypes then the method calls succeed as expected
>>>obj = comtypes.client.CreateObject("SMISEventHandler.ImgEvents")
>>>obj.Status(1, "success")
0
The library also works correctly when accessed from VB6. This suggests that the COM library itself is working correctly and the fault lies with win32com. This also seems related to the following question from StackOverflow that was never resolved (other than to use comtypes): "Member not found." error using win32com
comtypes is not a great solution for me in practice because I need the cross-thread marshalling abilities of win32com, so I am very keen to find a solution to this problem, but running out of ideas to try - if anybody can suggest some ways to get a better idea of what is going on, I will certainly try them.
Python: 3.9.12
pywin32: 303
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论