SetupDiGetDeviceInterfaceDetail

2006-02-16 Thread cafs
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 "NOO";}
   $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
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Packing variable or unknown structure

2005-06-02 Thread cafs
hello I am starting to learn how to import functions using
Win32::API

the following function outputs a pointer to a structure
and I understand how to use perls pack to "build" the required
structure.

WINSETUPAPI BOOL WINAPI
  SetupDiEnumDeviceInfo(
IN HDEVINFO  DeviceInfoSet,
IN DWORD  MemberIndex,
OUT PSP_DEVINFO_DATA  DeviceInfoData
);

typedef struct _SP_DEVINFO_DATA {
  DWORD  cbSize;
  GUID  ClassGuid;
  DWORD  DevInst;
  ULONG_PTR  Reserved;
} SP_DEVINFO_DATA, *PSP_DEVINFO_DATA;

SP_DEVINFO_DATA is represented as
$devdata = pack ( 'LL4LL', 28, 0, 0, 0 );

then setupdienumdeviceinfo can be called as
SetupDiEnumDeviceInfo( $devicedev, $index, $devdata );

my question is this; what if the structure is unknown?
how can I prepare a packed scalar of unknown size or
of variable size? 

BOOLEAN
  HidD_GetPreparsedData(
IN HANDLE  HidDeviceObject,
OUT PHIDP_PREPARSED_DATA  *PreparsedData
);

looking at MSDN online we get the following
"The internal structure of a _HIDP_PREPARSED_DATA 
structure is reserved for internal system use"
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Win32::API LPTSTR

2005-05-20 Thread cafs
Not sure if this is a resend, I needed to subscribe to this list:
I am trying to use Win32::API to import by prototype only;
of the functions I have tried the ones with type LPTSTR fail;
I would like to just use the prototypes because if its packing functions
Win32::API::Struct and Win32::API::Type - see the example in API.pm

example

use Win32::API;

#DWORD GetTempPath(
#  DWORD ccBuffer, 
#  LPTSTR lpszBuffer
#); 

#Win32::API->Import("kernel32", "DWORD GetTempPath(DWORD ccBuffer, LPTSTR 
lpszBuffer)",);
#this fails and causes generic a windows error when GetTempPath() is called

Win32::API->Import('kernel32', 'GetTempPath', 'NP', 'N');
#this of course works, but I would like to use the prototype
#the example at the end of API.pm demonstrates using the prototype

$lpszBuffer = " " x 80;
GetTempPath(80, $lpszBuffer);

print $lpszBuffer;
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs