| 
 | 
 
void CDlgReportPreview :: GetPrinterPara (TCHAR * szDevice, TCHAR szDriver, TCHAR * szOutput) 
{ 
HKEY hOpenKey1, hOpenKey2; 
long lResult = 0; 
DWORD dwKeyValueType = 0; 
DWORD dwKeyValueLength = 0; 
Ranch 
LPCTSTR keyName2 = L "Printers\\Ports"; 
// Changed the position of keyName2 used below, its value is not Printersuo1Ports 
CString str; 
str.Format (_T ("Driver")); 
LPCWSTR lpSubKey = TEXT ("Printers"); 
 
LPCTSTR dwKeyName2 = TEXT ("Port5"); 
 
CString keyName1 (L "Printers\\"); 
// LPTSTR keyName1 = L "Printers\\"; if so, the second time it is passed in, it will add the value of szDevice; 
TCHAR strKeyValue [500]; 
Ranch 
CComboBox * pCmbReg = (CComboBox *) GetDlgItem (IDC_COMBO_PRINTER); 
UpdateData (TRUE); 
CString strText; 
LPCTSTR lpctText; 
pCmbReg-> GetWindowText (strText); 
lpctText = (LPCTSTR) strText; 
wsprintf (szDevice, lpctText); 
Ranch 
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"; The value it returns is not what I want. 
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); 
} |   
 
 
 
 |