Home > Mobile >  QT5 equipment information
QT5 equipment information

Time:10-14

As title, mainly for usb printer docket information, then send instruction has fainted

CodePudding user response:

HDEVINFO hDevInfoSet;//device similar to handle
SP_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; If (bResult)
{
//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; If (bResult)
{
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
reference 3 floor adeng1919 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 of
try once, not the problem, thank you

CodePudding user response:

Bloggers, hello, how are you in Qt success calls SetupDiGetClassDevs function ()? I'm qtcreator ide development environment corresponding source file to add the # include & lt; Setupapi. H> And # include & lt; Windows. H> , but the compile-time errors:
D: \ QtProject/test1/test1/widget. The CPP: 309: error: undefined reference to ` _imp__SetupDiGetClassDevsW @ 16 '
Blogger is how to solve this error, please? I didn't find the problem, check the information,

CodePudding user response:

The hardware of the time to buy for the demo

CodePudding user response:

This printer manufacturers offer development components! Including demos, documentation, I have developed is very simple, basically routines are first call interface to obtain a singleton objects and get a printer printer factory), and then initialize printer, and then printing the instruction, which need your own function calls the Windows to get a handle to operate!
  •  Tags:  
  • Qt
  • Related