Bläddra i källkod

修复了xp下不能打印的问题

zhangyang 6 år sedan
förälder
incheckning
89cd4f02d3

BIN
bin/Win32/Debug/lewaimai_pos_windows/db/pos.db


BIN
bin/Win32/Release/lewaimai_pos_windows/db/pos.db


BIN
bin/Win32/Release/lewaimai_pos_windows/lewaimai_pos_windows.exe


BIN
bin/Win32/Release/setup/lewaimai_pos_windows_1.0.0.1.exe


+ 2 - 2
lewaimai_pos_windows/network/CLewaimaiHttpClient.cpp

@@ -141,12 +141,12 @@ bool CLewaimaiHttpClient::Request(std::string url, std::map<string, string> para
 		}
 	}
 
-	LOG_INFO("postString:" << postString.c_str());
+	//LOG_INFO("postString:" << postString.c_str());
 
 	CHttpClient m_httpClient;
 	int ret = m_httpClient.Posts(m_client.m_url + url, postString, response, NULL);
 
-	LOG_INFO("response:" << response.c_str());
+	//LOG_INFO("response:" << response.c_str());
 
 	if (ret == 0)
 	{

+ 19 - 4
lewaimai_pos_windows/tool/CPosPrinter.cpp

@@ -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;
 }