Defines methods for the stream objects in sequence.
| 8 | |
| 9 | |
| 10 | class ISequentialStream(IUnknown): |
| 11 | """Defines methods for the stream objects in sequence.""" |
| 12 | |
| 13 | _iid_ = GUID("{0C733A30-2A1C-11CE-ADE5-00AA0044773D}") |
| 14 | _idlflags_ = [] |
| 15 | |
| 16 | _methods_ = [ |
| 17 | # Note that these functions are called `Read` and `Write` in Microsoft's documentation, |
| 18 | # see https://learn.microsoft.com/en-us/windows/win32/api/objidl/nn-objidl-isequentialstream. |
| 19 | # However, the comtypes code generation detects these as `RemoteRead` and `RemoteWrite` |
| 20 | # for very subtle reasons, see e.g. https://stackoverflow.com/q/19820999/. We will not |
| 21 | # rename these in this manual import for the sake of consistency. |
| 22 | COMMETHOD( |
| 23 | [], |
| 24 | HRESULT, |
| 25 | "RemoteRead", |
| 26 | # This call only works if `pv` is pre-allocated with `cb` bytes, |
| 27 | # which cannot be done by the high level function generated by metaclasses. |
| 28 | # Therefore, we override the high level function to implement this behaviour |
| 29 | # and then delegate the call the raw COM method. |
| 30 | (["out"], POINTER(c_ubyte), "pv"), |
| 31 | (["in"], c_ulong, "cb"), |
| 32 | (["out"], POINTER(c_ulong), "pcbRead"), |
| 33 | ), |
| 34 | COMMETHOD( |
| 35 | [], |
| 36 | HRESULT, |
| 37 | "RemoteWrite", |
| 38 | (["in"], POINTER(c_ubyte), "pv"), |
| 39 | (["in"], c_ulong, "cb"), |
| 40 | (["out"], POINTER(c_ulong), "pcbWritten"), |
| 41 | ), |
| 42 | ] |
| 43 | |
| 44 | def RemoteRead(self, cb: int) -> tuple["_CArrayType[c_ubyte]", int]: |
| 45 | """Reads a specified number of bytes from the stream object into memory |
| 46 | starting at the current seek pointer. |
| 47 | """ |
| 48 | # Behaves as if `pv` is pre-allocated with `cb` bytes by the high level func. |
| 49 | pv = (c_ubyte * cb)() |
| 50 | pcb_read = pointer(c_ulong(0)) |
| 51 | self.__com_RemoteRead(pv, c_ulong(cb), pcb_read) # type: ignore |
| 52 | # return both `out` parameters |
| 53 | return pv, pcb_read.contents.value |
| 54 | |
| 55 | if TYPE_CHECKING: |
| 56 | |
| 57 | def RemoteWrite(self, pv: "_CArrayType[c_ubyte]", cb: int) -> int: |
| 58 | """Writes a specified number of bytes into the stream object starting at |
| 59 | the current seek pointer. |
| 60 | """ |
| 61 | ... |
| 62 | |
| 63 | |
| 64 | # fmt: off |