String data not properly read from Windows Registry

  • Thread starter Thread starter CrimeMaster
  • Start date Start date
C

CrimeMaster

Hi
i have made a Key under the HKEY_LOCAL_MACHINE\Software\My
Toolbar\Setting.
i have placed some values under the Setting key.
i m trying to access the values under that key and want to map them to
a dialog box ,means they should be visible in their corresponding Edit
controls when i display the dialog.i have used the following code in
OnInitDialog() function to map the values to their corresponding
controls but when the dialog displayed some values are repeatedly shown

in different controls.tell me where i m doing a mistake .

CRegKey regKey;
TCHAR szPath[] = _T("SOFTWARE\\MySpace.com
ToolBar\\Setting");
TCHAR szBuff[1024];
DWORD dwSize=dwSize = sizeof(szBuff)/sizeof(szBuff[0]);
LONG err=regKey.Open(HKEY_LOCAL_MACHINE,szPath);
if (err!=ERROR_SUCCESS)
regKey.Close();


regKey.QueryValue(szBuff, _T("FirstName"), &dwSize);
m_FirstName = szBuff;


regKey.QueryValue(szBuff, _T("LastName"), &dwSize);
m_LastName= szBuff;
regKey.QueryValue(szBuff, _T("PresentAddress"), &dwSize);
m_PresentAddress= szBuff;


regKey.QueryValue(szBuff, _T("PermanentAddress"), &dwSize);
m_PermanentAddress = szBuff;


regKey.QueryValue(szBuff, _T("City"), &dwSize);
m_City= szBuff;


regKey.QueryValue(szBuff, _T("Country"), &dwSize);
m_Country = szBuff;
regKey.QueryValue(szBuff, _T("ZipCode"), &dwSize);
m_Zip= szBuff;


regKey.QueryValue(szBuff, _T("PhoneNo"), &dwSize);
m_Phone=szBuff;
regKey.QueryValue(szBuff, _T("MobileNo"), &dwSize);
m_Mobile = szBuff;
regKey.QueryValue(szBuff, _T("AutofillEmail"), &dwSize);
m_EmailAddress = szBuff;


UpdateData(false);


when the dialog displayed often LastName value from registry is
displayed in the m_PresentAddress and m_PermanentAddress edit
controls.and City Value fron registry id
also displayed in m_Country edit control.in the same way some values
are retrieving from registry and when i try to map them with edit
controls on the Dialog box .why did they are ?
 
i have made a Key under the HKEY_LOCAL_MACHINE\Software\My
Toolbar\Setting.
i have placed some values under the Setting key.
i m trying to access the values under that key and want to map them to
a dialog box ,means they should be visible in their corresponding Edit
controls when i display the dialog.i have used the following code in
OnInitDialog() function to map the values to their corresponding
controls but when the dialog displayed some values are repeatedly shown

in different controls.tell me where i m doing a mistake .

CRegKey regKey;
TCHAR szPath[] = _T("SOFTWARE\\MySpace.com
ToolBar\\Setting");
TCHAR szBuff[1024];
DWORD dwSize=dwSize = sizeof(szBuff)/sizeof(szBuff[0]);
LONG err=regKey.Open(HKEY_LOCAL_MACHINE,szPath);
if (err!=ERROR_SUCCESS)
regKey.Close();


regKey.QueryValue(szBuff, _T("FirstName"), &dwSize);
m_FirstName = szBuff;


regKey.QueryValue(szBuff, _T("LastName"), &dwSize);
m_LastName= szBuff;
regKey.QueryValue(szBuff, _T("PresentAddress"), &dwSize);
m_PresentAddress= szBuff;

2 things:
- you don't check the return value of QueryValue. shame on you.
- you don't re-initialize the dwSize value before each call to QueryValue.
from MSDN: "pdwCount
The size of the string data. Its value is initially set to the size of the
szValue buffer."
you should initialize it to the max string size before each call.

another thing is that QueryValue is depreceated in favor of this method:
LONG QueryValue(
LPCTSTR pszValueName,
DWORD* pdwType,
void* pData,
ULONG* pnBytes
) throw( );

also, this looks weird:
DWORD dwSize=dwSize = sizeof(szBuff)/sizeof(szBuff[0]);

--

Kind regards,
Bruno.
(e-mail address removed)
Remove only "_nos_pam"
 
CrimeMaster said:
Hi
i have made a Key under the HKEY_LOCAL_MACHINE\Software\My
Toolbar\Setting.
i have placed some values under the Setting key.
i m trying to access the values under that key and want to map them to
a dialog box ,means they should be visible in their corresponding Edit
controls when i display the dialog.i have used the following code in
OnInitDialog() function to map the values to their corresponding
controls but when the dialog displayed some values are repeatedly shown

in different controls.tell me where i m doing a mistake .

regKey.QueryValue(szBuff, _T("City"), &dwSize);
m_City= szBuff;

In addition to what Bruno sais,
why don't you use
LONG result = regKey.QueryStringValue(_T("City"), szBuff, &dwSize);
 
Egbert said:
In addition to what Bruno sais,
why don't you use
LONG result = regKey.QueryStringValue(_T("City"), szBuff, &dwSize);


Thanks dear
But not discourage me
its working.

Crime Master.
 
Back
Top