[python-win32] USB Insertion Extrinsic Event exists?

Tim Golden mail at timgolden.me.uk
Mon Feb 15 17:09:06 CET 2010


On 14/02/2010 09:41, Tim Golden wrote:
> Just realised that pywin32 ships with an example of this.
>   From my site-packages directory:
>
> win32\Demos\service\serviceEvents.py
>
> I haven't had the chance to try it out, but let is know if it does
> meet your case.

Well I've given it a go and, naturally, it works ok. Except...

As documented(ish) (look under Remarks):

   http://msdn.microsoft.com/en-us/library/aa363431%28VS.85%29.aspx

It'll only handle DBT_DEVTYP_DEVICEINTERFACE or DBT_DEVTYP_HANDLE

That wouldn't matter too much since the device interface event
returns the name of the volume, which one can use to good effect.
Except...

The pywin32gui_struct library which parses the stuff coming back
from the events assumes that the string is NUL-terminated. But
it's a UTF16 Unicode string so it's "nul-terminated" after the
first byte. I'll raise this as a bug on the pywin32 tracker, but
meanwhile I'll try to get an example which works around it by
parsing the header manually, as per the windows message example.
Or I could monkey-patch the win32gui_struct module. Might be
easier.

TJG


More information about the python-win32 mailing list