Hello all; I have a very rough beginnings of a script
that I was creating to access HID devices through API.
The following script was working on windows 98 but 
on XP, it fails when SetupDiGetDeviceInterfaceDetail
is called. I am not sure if I am packing the required
pointers correctly or if I am hitting up against a
security issue with SP2.
SetupDiGetDeviceInterfaceDetail has the option of passing
a null pointer in the place of DeviceInterfaceDetailData
to receive the RequiredSize, but I still get the same
crash: typical XP screen prompting to send the error report.

script is as follows:


use Win32::API::Prototype;
$NULL = pack("L4");
ApiLink ('kernel32', 'DWORD GetLastError()') or die;
ApiLink ('hid', 'HANDLE HidD_GetHidGuid( LPGUID HidGuid )') or die;
ApiLink ('setupapi', 'HANDLE SetupDiGetClassDevs(
                        LPGUID classguid, 
                        LPTSTR Enumerator,
                        HWND  hwndParent, 
                        DWORD  Flags 
                        )') or die;
ApiLink ('setupapi', 'BOOL SetupDiEnumDeviceInterfaces(
                        HANDLE DeviceInfoSet, 
                        LPSP_DEVINFO_DATA DeviceInfoData,
                        LPGUID InterfaceClassGuid, 
                        DWORD MemberIndex,
                        LPSP_DEVICE_INTERFACE_DATA DeviceInterfaceData 
                        )') or die;
ApiLink ('setupapi', 'BOOL SetupDiGetDeviceInterfaceDetail(
                        HANDLE  DeviceInfoSet,
                        LPSP_DEVICE_INTERFACE_DATA  DeviceInterfaceData,
                        LPSP_DEVICE_INTERFACE_DETAIL_DATA 
DeviceInterfaceDetailData,
                        DWORD  DeviceInterfaceDetailDataSize, 
                        LPDWORD RequiredSize,
                        PSP_DEVINFO_DATA  DeviceInfoData 
                        )') or die;
ApiLink ('setupapi', 'BOOL SetupDiDestroyDeviceInfoList( 
                        HANDLE DeviceInfoSet )') or die;
ApiLink ('kernel32', 'HANDLE CreateFile(
                        LPCTSTR lpFileName,
                        DWORD dwDesiredAccess,
                        DWORD dwShareMode,
                        LPSECURITY_ATTRIBUTES lpSecurityAttributes,
                        DWORD dwCreationDisposition,
                        DWORD dwFlagsAndAttributes,
                        HANDLE hTemplateFile )') or die;
ApiLink ('hid', 'BOOL HidD_GetAttributes(
                        HANDLE HidDeviceObject, 
                        LPHIDD_ATTRIBUTES Attributes 
                        )') or die;



$hidguid = pack('L4');
HidD_GetHidGuid($hidguid) or die;
$deviceset = SetupDiGetClassDevs( $hidguid, 0, 0, 0x02 | 0x10);
      if ( $deviceset == -1 ){ die "unable to get class devs"; }
$devicedata = pack ( 'LL4LL', 28, 0, 0, 0 ); #sp_devinfo_data

$devintdata = pack ( 'LL4LL', 28, 0, 0, 0 ); #sp_device_interface_data
$devintdetail = pack ( 'LCL32', 5 ); #sp_device_interface_detail_data
$size       = pack ( 'L' );
$hidattrib  = pack ( 'LSSS' );


for( $count = 0; ; $count++ ){

   if ( ! SetupDiEnumDeviceInterfaces( $deviceset, 0, $hidguid, $count, 
$devintdata )){
         if  ( GetLastError() != 259 ){ print GetLastError(); 
                             die 'error while enumerating devices';}
                                        last;}
###script fails here, typical XP error dialog is displayed
   if ( ! SetupDiGetDeviceInterfaceDetail( 
       $deviceset, $devintdata, $devintdetail, 128, $size, $devicedata )
               ){print GetLastError(); die "NOOOOOOOOOO";}
   $path = substr($devintdtal, 4);
   $file = CreateFile($path, 0x80 | 0x40, 0x10 | 0x20, 0, 3, 0, 0);
   HidD_GetAttributes($file, $hidattrib) or die "hid go down the hole";
   

next; }

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to