Re: RegQueryValueEx retrieved only one letter



fifth wrote:
I want to retrieve the string value of a register key which is "C:
\program files\test", but every time I only get one letter as "C"
returned. My code is as follows, can somebody help me find out what
happened?

///////////////////////////////////////////////////////////////////////////////////////
HKEY hKEY
LPCTSTR data_Set=_T("Software\\test\\Settings");
long ret0=(::RegOpenKeyEx (HKEY_CURRENT_USER, data_Set, 0,
KEY_READ, &hKEY));
if(ret0!=ERROR_SUCCESS)
AfxMessageBox(_T("error: cannot open hKEY!"));

char *szPath = new char[256];
DWORD type_1=REG_SZ ;
DWORD cbData_1=80;
long ret1=::RegQueryValueEx(hKEY,_T("InstallPath"), NULL,&type_1,
(BYTE *)szPath, &cbData_1);
if(ret1!=ERROR_SUCCESS)
AfxMessageBox(_T("error, cannot query hKEY!"));

::RegCloseKey(hKEY);

USES_CONVERSION;
AfxMessageBox(A2T(ch));
delete szPath;

fifth:

Do not use char, new, 256, or A2T:

TCHAR szPath[_MAX_PATH];

long ret1=::RegQueryValueEx(hKEY,_T("InstallPath"), NULL,&type_1,
(BYTE *)szPath, &cbData_1);

--
David Wilkinson
Visual C++ MVP
.



Relevant Pages

  • Re: RegOpenKeyEx returns always ERROR_FILE_NOT_FOUND!
    ... It is reporting that the path you specified does not exist, ... >the following problem drives me crazy, I'm on the verge to go berserk! ... > HKEY hKey; ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: get last char in a string
    ... Now I can't use the _itoa_s function because it requires a char type. ... David Wilkinson ... Visual C++ MVP ...
    (microsoft.public.vc.language)
  • Re: how do I convert CStringW to UTF-8?
    ... how do I convert CStringW to UTF-8 for output into a CStringA or a ... David Wilkinson ... Visual C++ MVP ...
    (microsoft.public.vc.mfc)

Loading