CodePudding user response:
HDEVINFO hDevInfoSet;//device similar to handleSP_DEVINFO_DATA spDevInfoData;//equipment detailed property information
SP_DEVICE_INTERFACE_DATA ifData;
PSP_DEVICE_INTERFACE_DETAIL_DATA pDetail;
Int nCount;
Int nTotle;
BOOL bResult;
QString strUSBPrint="USB printer support";
//get a cento handle the GUID related equipment information
HDevInfoSet=: : SetupDiGetClassDevs (lpGuid,//a class GUID
NULL,//no keyword
NULL,//do not specify a handle to the parent window
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);//the existing equipment
//qDebug () & lt;
//fail...
If (hDevInfoSet==INVALID_HANDLE_VALUE)
{
return 0;//not find equipment
}
//application device interface data space
PDetail=(PSP_DEVICE_INTERFACE_DETAIL_DATA) : : GlobalAlloc (LMEM_ZEROINIT INTERFACE_DETAIL_SIZE);
PDetail - & gt; The cbSize=sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA);
//qDebug () & lt;
NTotle=1;
NCount=0;
BResult=TRUE;
//equipment serial number=0,... One by one test equipment interface, until failure
While (bResult)
//for (DWORD I=0; SetupDiEnumDeviceInfo (hDevInfoSet, I, & amp; SpDevInfoData); I++)
{
NTotle++;
SpDevInfoData. CbSize=sizeof (SP_DEVINFO_DATA);
//enumerated in accordance with the GUID equipment interface
BResult=: : SetupDiEnumDeviceInfo (
HDevInfoSet,//equipment information cento handle
(ULONG) nTotle,//equipment serial number of the device information set
& SpDevInfoData);//device interface information
If (bResult)
{
DWORD DataT;
TCHAR buf [MAX_PATH];
DWORD nSize=0;
//get a friendly name or device description
If (SetupDiGetDeviceRegistryProperty (hDevInfoSet, & amp; SpDevInfoData SPDRP_FRIENDLYNAME, & amp; DataT, (PBYTE) buf, sizeof (buf), & amp; NSize))
{}
Else if (SetupDiGetDeviceRegistryProperty (hDevInfoSet, & amp; SpDevInfoData SPDRP_DEVICEDESC, & amp; DataT, (PBYTE) buf, sizeof (buf), & amp; NSize))
{}
The else {//lstrcpy (buf, _T (" Unknown "));
}
//is looking for equipment type
if (_tcscmp (buf, QStringToTCHAR (strUSBPrint))!=0)
{
continue;
}
IfData. CbSize=sizeof (ifData);
//enumerated in accordance with the GUID equipment interface
BResult=: : SetupDiEnumDeviceInterfaces (cento hDevInfoSet,//equipment information handle
NULL,//no extra equipment description
LpGuid,//GUID
(ULONG) nTotle,//equipment serial number of the device information set
& IfData);//device interface information
//qDebug () & lt; <" BResult "& lt;
{
//the device interface details (device path)
BResult=SetupDiGetInterfaceDeviceDetail (
HDevInfoSet,//equipment information cento handle
& IfData,//device interface information
PDetail,//device interface details (device path)
INTERFACE_DETAIL_SIZE,//output buffer size
NULL,//no need to calculate the output buffer size (direct value)
NULL);//does not need additional device description
//qDebug () & lt; <" BResult "& lt;
{
Wcscpy_s (pszDevicePath [nCount], 256, pDetail - & gt; DevicePath);
//copy device path to the output buffer
NCount++;
}
}
}
}
//release device interface data space
: : GlobalFree (pDetail);
//close the device information cento handle
: : SetupDiDestroyDeviceInfoList (hDevInfoSet);
Return nCount;
O great god have a look at the code, when to perform here, usb printer is connected on the docket, but wrong judgment, there added debugging information,
CodePudding user response:
These printers are commonly and drives the development of documents, their direct instructions also have specific standard agreement, according to specific standard protocols, send com information,CodePudding user response:
QString strUSBPrint="USB printer support";See if there are may be the problem of coding, Qt for Chinese to write directly in the code inside there is a problem
CodePudding user response:
The