Skip to content

Commit

Permalink
[test\test_stream.py] Use WinDLL instead of oledll/windll
Browse files Browse the repository at this point in the history
Partially fix enthought#735
  • Loading branch information
moi15moi committed Jan 12, 2025
1 parent 548661f commit 2c26410
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions comtypes/test/test_stream.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import unittest as ut
from ctypes import (
HRESULT,
POINTER,
WinDLL,
byref,
c_ubyte,
c_ulonglong,
pointer
)
from ctypes.wintypes import BOOL, HGLOBAL, ULARGE_INTEGER

from ctypes import POINTER, byref, c_bool, c_ubyte, c_ulonglong, oledll, pointer
import comtypes
import comtypes.client

comtypes.client.GetModule("portabledeviceapi.dll")
Expand All @@ -13,11 +21,22 @@
STREAM_SEEK_CUR = 1
STREAM_SEEK_END = 2

_ole32 = WinDLL("ole32")

_CreateStreamOnHGlobal = _ole32.CreateStreamOnHGlobal
_CreateStreamOnHGlobal.argtypes = [HGLOBAL, BOOL, POINTER(POINTER(IStream))]
_CreateStreamOnHGlobal.restype = HRESULT

_shlwapi = WinDLL("shlwapi")

_IStream_Size = _shlwapi.IStream_Size
_IStream_Size.argtypes = [POINTER(IStream), POINTER(ULARGE_INTEGER)]
_IStream_Size.restype = HRESULT

def _create_stream() -> IStream:
# Create an IStream
stream = POINTER(IStream)() # type: ignore
comtypes._ole32.CreateStreamOnHGlobal(None, c_bool(True), byref(stream))
_CreateStreamOnHGlobal(None, True, byref(stream))
return stream # type: ignore


Expand Down Expand Up @@ -92,7 +111,7 @@ def test_SetSize(self):
stream = _create_stream()
stream.SetSize(42)
pui = pointer(c_ulonglong())
oledll.shlwapi.IStream_Size(stream, pui)
_IStream_Size(stream, pui)
self.assertEqual(pui.contents.value, 42)


Expand Down

0 comments on commit 2c26410

Please sign in to comment.