Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

The errors that occur when replacing ctypes.windll.foobar/ctypes.WinDLL("foobar") with ctypes.oledll.foobar/ctypes.OleDLL("foobar") #129010

Copy link
Copy link
Open
@junkmd

Description

@junkmd
Issue body actions

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.foobar was originally used, I think it would be better to use OleDLL("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 argtypes and restype for each function.

I choosed WinDLL because I observate weird behaviour with OleDLL. For example, for this line, if I change windll.oleaut32.SysAllocStringLen to _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 long

I am unsure why this issue only occurs with OleDLL, but it seems very strange to me. According to the ctypes documentation, the only difference between OleDLL and WinDLL is the default restype: HRESULT for OleDLL and int for WinDLL. However, there must be a more significant underlying difference, as WinDLL does not fail under the same circumstances.

I had assumed that the only difference between oledll.foobar and OleDLL("foobar") was whether or not they were shared. (Edited: I was confused. See #129010 (comment))
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.