|
|
@@ -20,10 +20,13 @@ CPosPrinter::~CPosPrinter()
|
|
|
bool CPosPrinter::InitShouyin()
|
|
|
{
|
|
|
//遍历USB设备,找到POS打印机路径
|
|
|
+
|
|
|
//设备路径
|
|
|
TCHAR* szDevicePath[MAX_DEVICE];
|
|
|
+
|
|
|
//设置中文字符
|
|
|
setlocale(LC_CTYPE, "chs");
|
|
|
+
|
|
|
TCHAR* Port = NULL;
|
|
|
|
|
|
//分配需要的空间
|
|
|
@@ -34,6 +37,7 @@ bool CPosPrinter::InitShouyin()
|
|
|
|
|
|
//取设备路径
|
|
|
int nDevice = GetDevicePath((LPGUID)&USB_GUID, szDevicePath);
|
|
|
+ LOG_INFO("nDevice:" << nDevice);
|
|
|
int i = 0;
|
|
|
|
|
|
while(i < nDevice)
|
|
|
@@ -653,7 +657,11 @@ int CPosPrinter::GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath)
|
|
|
int nCount;
|
|
|
int nTotle;
|
|
|
BOOL bResult;
|
|
|
+
|
|
|
+ //这2个字符串,用于根据usb的名字对比是否为打印机设备
|
|
|
wstring strUSBPrint = TEXT("USB 打印支持");
|
|
|
+ wstring strUSBPrint_EN = L"USB Printing Support";
|
|
|
+
|
|
|
// 取得一个该GUID相关的设备信息集句柄
|
|
|
hDevInfoSet = ::SetupDiGetClassDevs(lpGuid, // class GUID
|
|
|
NULL, // 无关键字
|
|
|
@@ -663,7 +671,7 @@ int CPosPrinter::GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath)
|
|
|
// 失败...
|
|
|
if(hDevInfoSet == INVALID_HANDLE_VALUE)
|
|
|
{
|
|
|
- printf("failed \r\n");
|
|
|
+ LOG_INFO("failed \r\n");
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -695,25 +703,28 @@ int CPosPrinter::GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath)
|
|
|
if(SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
|
|
|
SPDRP_FRIENDLYNAME, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
|
|
|
{
|
|
|
+
|
|
|
}
|
|
|
else if(SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
|
|
|
SPDRP_DEVICEDESC, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
|
|
|
{
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
lstrcpy(buf, _T("Unknown"));
|
|
|
}
|
|
|
|
|
|
- _tprintf(_T("buf = %s \r\n"), buf);
|
|
|
+ //LOG_INFO("buf:" << buf);
|
|
|
|
|
|
//是否是要找的设备类型
|
|
|
- if(_tcscmp(buf, strUSBPrint.c_str()) != 0)
|
|
|
+ if(_tcscmp(buf, strUSBPrint.c_str()) != 0 && _tcscmp(buf, strUSBPrint_EN.c_str()) != 0)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- _tprintf(_T("OK\r\n"));
|
|
|
+ //LOG_INFO("找到打印的USB设备!");
|
|
|
+
|
|
|
ifData.cbSize = sizeof(ifData);
|
|
|
// 枚舉符合該GUID的設備接口
|
|
|
bResult = ::SetupDiEnumDeviceInterfaces(
|
|
|
@@ -738,8 +749,10 @@ int CPosPrinter::GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath)
|
|
|
{
|
|
|
// 复制设备路径到输出缓冲区
|
|
|
::_tcscpy_s(pszDevicePath[nCount], 256, pDetail->DevicePath);
|
|
|
+
|
|
|
// 调整计数值
|
|
|
nCount++;
|
|
|
+
|
|
|
_tprintf(_T("Cnt = %d,pDetail->DevicePath =%s\r\n"), nCount, pDetail->DevicePath);
|
|
|
}
|
|
|
}
|
|
|
@@ -748,8 +761,10 @@ int CPosPrinter::GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath)
|
|
|
|
|
|
// 释放设备接口数据空间
|
|
|
::GlobalFree(pDetail);
|
|
|
+
|
|
|
// 关闭设备信息集句柄
|
|
|
::SetupDiDestroyDeviceInfoList(hDevInfoSet);
|
|
|
+
|
|
|
return nCount;
|
|
|
}
|
|
|
|