# Include <VCL. h> # Include <dir. h> # Include <setupapi. h> # Include "C:/winddk/3790/INC/DDK/w2k/usbdi. H" # Include "C:/winddk/3790/INC/DDK/w2k/devictl. H" # Include <initguid. h> //--------------------------------------------------------------------------- // The following must be the guid value of the driver. Here I am writing a number in disorder. Define_guid (usb_driver_guid, 0x12345678, 0 xabcd, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0x00 ); //--------------------------------------------------------------------------- Handle openonedevice (hdevinfo hdvcinfo, psp_interface_device_data dvcinfodata, char * sdevnamebuf) { Handle Hout = invalid_handle_value;Ulong ireqlen = 0; Setupdigetinterfacedevicedetail (hdvcinfo, dvcinfodata, null, 0, & ireqlen, null ); Ulong idevdatalen = ireqlen; // sizeof (sp_fnclass_device_data) + 512; Psp_interface_device_detail_data pdevdata = (psp_interface_device_detail_data) malloc (idevdatalen ); Pdevdata-> cbsize = sizeof (sp_interface_device_detail_data ); If (setupdigetinterfacedevicedetail (hdvcinfo, dvcinfodata, pdevdata, idevdatalen, & ireqlen, null )) { Strcpy (sdevnamebuf, pdevdata-> devicepath ); Hout = createfile (pdevdata-> devicepath, generic_read | generic_write, file_pai_read | file_pai_write, null, open_existing, 0, null ); } Free (pdevdata ); Return Hout; } //--------------------------------------------------------------------------- Handle openusbdevice (const guid * pguid, char * sdevnamebuf) { Handle Hout = invalid_handle_value; Hdevinfo = setupdigetclassdevs (pguid, null, null, digcf_present | digcf_interfacedevice ); Sp_interface_device_data deviceinfodata; Deviceinfodata. cbsize = sizeof (sp_interface_device_data ); Ulong nguesscount = maxlong; For (ulong idevindex = 0; idevindex <nguesscount; idevindex ++) { If (setupdienumdeviceinterfaces (hdevinfo, 0, pguid, idevindex, & deviceinfodata )) { If (Hout = openonedevice (hdevinfo, & deviceinfodata, sdevnamebuf ))! = Invalid_handle_value) Break; } Else if (getlasterror () = error_no_more_items) // no more items { Break; } } Setupdidestroydeviceinfolist (hdevinfo ); Return Hout; } //--------------------------------------------------------------------------- Bool getusbdevicefilename (const guid * pguid, char * sdevnamebuf) { Handle hdev = openusbdevice (pguid, sdevnamebuf ); If (hdev! = Invalid_handle_value) { Closehandle (hdev ); Return true; } Return false; } //--------------------------------------------------------------------------- Handle openmydevice () { Char devicename [maxpath] = ""; Return openusbdevice (& usb_driver_guid, devicename ); } //--------------------------------------------------------------------------- Handle openmydevpipe (const char * pipename) { Char devicename [maxpath] = ""; If (getusbdevicefilename (& usb_driver_guid, devicename )) { Strcat (devicename ,"//"); Strcat (devicename, pipename ); Return createfile (devicename, generic_write | generic_read, file_pai_write | file_pai_read, null, open_existing, 0, null ); } Return invalid_handle_value; } //--------------------------------------------------------------------------- |