Python Win32 API question.

yaipa h. yaipa at yahoo.com
Fri Jan 3 00:42:30 EST 2003


David,

This is great. Thanks

I have the DDK, but am new to it and sometimes where they poke things
doesn't make much sense. :(.  'winioctl.h' is the lead I need for the
Constant codes.  The code below is a great help. It is always easier to
learn new techniques when you already have something that works already.

Regards of the best kind,

Alan Haffner

David Bolen <db3l at fitlinxx.com> wrote in message news:<u8yy3a5ep.fsf at fitlinxx.com>...
> yaipa at yahoo.com (yaipa h.) writes:
> 
> > Finally, for the big points. Anyone belive that I will be able to use
> > any of the 'IOCTL_*' enumerated values from the MFC toolkit with the 
> > win32file.DeviceIoControl library method? It's looking more and more 
> > like I will need to call a COM/DLL from my Python code to get this info. :((
> 
> Yes, you should be able to make the calls you want directly from
> Python.  I agree however, that unless you have a development kit it
> may be tricky to figure out what they are, since they are not built
> into win32all.  In my case, I just reference the winioctl.h file from
> my VC installation.  If you don't have some sort of developers kit, it
> looks like other development environments like Cygwin (and probably
> MingW) include this header as part of their win32 API collection, so
> you can obtain it that way.
> 
> Using the functions themselves are as documented in MSDN -
> DeviceIoControl is part of the Win32 core platform API, not MFC.  You
> have to make sure that the buffer size you request in the
> DeviceIoControl function matches the documented structure, and then
> unpack the buffer manually based on that structure definition.  But
> all of that information is available in MSDN.
> 
> > Thanks. An example IOCTL_ follows.
> > 
> > Yaipa.h
> > 
> > 'IOCTL_DISK_GET_DRIVE_GEOMETRY' Operation
> 
> Here's some example code using this particular call (note I've
> hardcoded the IOCTL constant following interpretation of winioctl.h):
> 
>           - - - - - - - - - - - - - - - - - - - - - - - - -
> import struct
> import win32api
> import win32file
> 
> if __name__ == "__main__":
> 
>     print 'Checking disk C:'
> 
>     info = win32api.GetVolumeInformation('c:\\')
>     print 'Filesystem:', info[-1]
> 
>     hDisk = win32file.CreateFile(r'\\.\PhysicalDrive0',
>                                  0,
>                                  win32file.FILE_SHARE_READ|
>                                  win32file.FILE_SHARE_WRITE,
>                                  None,
>                                  win32file.OPEN_EXISTING,
>                                  0,
>                                  None)
> 
>     IOCTL_DISK_GET_DRIVE_GEOMETRY=0x70000
> 
>     info = win32file.DeviceIoControl(hDisk,
>                                      IOCTL_DISK_GET_DRIVE_GEOMETRY,
>                                      '',24)
> 
>     # Values = (cylinders[high],cylinders[low],media_type,
>     #           tracks_per_cylinder,sectors_per_track,bytes_per_sector)
>     values = struct.unpack('6L',info)
> 
>     cylinders = (values[1]<<32)+values[0]
>     size = cylinders * values[3] * values[4] * values[5]
> 
>     print 'Total disk space: %d (%dMB)' % (size,size/(1024*1024))
>           - - - - - - - - - - - - - - - - - - - - - - - - -
> 
> 
> --
> -- David




More information about the Python-list mailing list