In Python 3.2 I am creating a Structure object from the data returned by the ctypes.windll.kernel32.DeviceIoControl function. After this is done I can access the Structure f
Some observations:
DevIoCtl
should be called with byref(BytesReturned)
.ctypes.cast
's first argument must be an "object that can be interpreted as a pointer".
What you are casting, however, is a raw bytes
object (from output[:BytesReturned.value]
).__DeviceIoControl
is a new Python bytes
object. The original reference to ctypes array object has gone out of scope. So, it's entirely possible that it has been garbage collected and/or reused.FWIW, I played around with Windows IOCTL dispatch using ctypes just for the heck of it. Also using \\.\PysicalDrive0
and IOCTL_DISK_GET_DRIVE_GEOMETRY
.
I made this gist.