|
void CDlgReportPreview::GetPrinterPara(TCHAR *szDevice,TCHAR szDriver,TCHAR *szOutput)
{
HKEY hOpenKey1,hOpenKey2;
long lResult = 0;
DWORD dwKeyValueType = 0;
DWORD dwKeyValueLength = 0;
LPCTSTR keyName2 = L"Printers\\Ports";
//换了下面用到keyName2位置它的值不是Printers\Ports
CString str;
str.Format(_T("Driver"));
LPCWSTR lpSubKey = TEXT("Printers");
LPCTSTR dwKeyName2 = TEXT("Port5");
CString keyName1(L"Printers\\");
// LPTSTR keyName1 = L"Printers\\";如果是这样,第二次传入它的会添加了szDevice的值;
TCHAR strKeyValue[500];
CComboBox* pCmbReg = (CComboBox*)GetDlgItem(IDC_COMBO_PRINTER);
UpdateData(TRUE);
CString strText;
LPCTSTR lpctText;
pCmbReg->GetWindowText(strText);
lpctText = (LPCTSTR)strText;
wsprintf(szDevice,lpctText);
keyName1 += lpctText;
// wcscat(keyName1,lpctText);
lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,keyName1,0,0,&hOpenKey1);
ASSERT(lResult == ERROR_SUCCESS);
//read szDevice, szDriver and szOutput value
ZeroMemory(strKeyValue,sizeof(TCHAR)*50);
dwKeyValueLength = sizeof(TCHAR)*50;
lResult = RegQueryValueEx(hOpenKey1,str,0,&dwKeyValueType,
(BYTE*)strKeyValue,&dwKeyValueLength);
ASSERT(lResult == ERROR_SUCCESS);
wsprintf(szDriver,strKeyValue);
RegCloseKey(hOpenKey1);
//LPCTSTR keyName2 = L"Printers\\Ports"; 它返回的值不是我想要的。
lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,keyName2,0,0,&hOpenKey2);
ASSERT(lResult == ERROR_SUCCESS);
ZeroMemory(strKeyValue,sizeof(TCHAR)*500);
lResult = RegQueryValueEx(hOpenKey2,dwKeyName2,0,&dwKeyValueType,
(BYTE*)strKeyValue,&dwKeyValueLength);
ASSERT(lResult == ERROR_SUCCESS);
wsprintf(szOutput,strKeyValue);
RegCloseKey(hOpenKey2);
} |
|