-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Description
Bug report
Bug description:
In enthought/comtypes#735, @moi15moi suggested avoiding the use of shared DLL objects, and work was attempted to implement this.
Replacing windll.foobar with WinDLL("foobar") and oledll.foobar with OleDLL("foobar") seemed like the appropriate approach.
However, when using OleDLL("foobar"), behavior like the one described in this comment occurred.
For the parts where
oledll.foobarwas originally used, I think it would be better to useOleDLL("foobar").
What do you think?I think it's better to only keep OleDLL or WinDLL to have more consistent code. Having both of them is pretty useless since I specify the
argtypesandrestypefor each function.I choosed
WinDLLbecause I observate weird behaviour withOleDLL. For example, for this line, if I changewindll.oleaut32.SysAllocStringLento_oleaut32.SysAllocStringLen, I get this error when I run the tests:File "C:\Users\moi15moi\Documents\GitHub\comtypes\comtypes\test\test_showevents.py", line 24, in comtypes.test.test_showevents.ShowEventsExamples.StdFont_ShowEvents Failed example: font.Name = 'Arial' Exception raised: Traceback (most recent call last): File "C:\Users\moi15moi\AppData\Local\Programs\Python\Python311\Lib\doctest.py", line 1353, in __run exec(compile(example.source, filename, "single", File "<doctest comtypes.test.test_showevents.ShowEventsExamples.StdFont_ShowEvents[5]>", line 1, in <module> font.Name = 'Arial' ^^^^^^^^^ File "C:\Users\moi15moi\Documents\GitHub\comtypes\comtypes\_post_coinit\_cominterface_meta_patcher.py", line 33, in __setattr__ object.__setattr__(self, self.__map_case__.get(name.lower(), name), value) File "C:\Users\moi15moi\Documents\GitHub\comtypes\comtypes\_memberspec.py", line 514, in fset return obj.Invoke(memid, value, _invkind=invkind) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\moi15moi\Documents\GitHub\comtypes\comtypes\automation.py", line 879, in Invoke dp = self.__make_dp(_invkind, *args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\moi15moi\Documents\GitHub\comtypes\comtypes\automation.py", line 854, in __make_dp array[i].value = a ^^^^^^^^^^^^^^ File "C:\Users\moi15moi\Documents\GitHub\comtypes\comtypes\automation.py", line 290, in _set_value self._.c_void_p = _SysAllocStringLen(value, len(value)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "_ctypes/callproc.c", line 1000, in GetResult OverflowError: Python int too large to convert to C longI am unsure why this issue only occurs with
OleDLL, but it seems very strange to me. According to the ctypes documentation, the only difference betweenOleDLLandWinDLLis the defaultrestype:HRESULTforOleDLLandintforWinDLL. However, there must be a more significant underlying difference, asWinDLLdoes not fail under the same circumstances.
I had assumed that the only difference between (Edited: I was confused. See #129010 (comment))oledll.foobar and OleDLL("foobar") was whether or not they were shared.
Could the cause of this behavior lie within the C extension or the cffi layer?
(See also #129010 (comment) as a minimal reproducer.)
CPython versions tested on:
3.11
Operating systems tested on:
Windows