pskyboy
Dec 24th, 2001, 12:00 PM
Hey Guys
Can anyone see a problem with this code its meant to read a value out of a string in teh registry and there is definately a value there. All this does though is display 3 random characters. The dword returns the right length of the string though.
Thanks for the help
Peter
TCHAR sInstallDirectory[MAX_PATH];
BYTE sInstallDirectoryUNI[MAX_PATH];
DWORD dwLengthOfInstallDirectory = NULL;
HKEY hUninstallInfo;
RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\RCAS\\UninstallInfo", 0, KEY_ALL_ACCESS, &hUninstallInfo);
if(RegQueryValueEx(hUninstallInfo, "InstallDirectory", NULL, NULL, &sInstallDirectoryUNI[0], &dwLengthOfInstallDirectory) == ERROR_SUCCESS)
{
TCHAR sTest[10];
ultoa(dwLengthOfInstallDirectory, sTest, 10);
AfxMessageBox(sTest);
for(int i = 0; i <= dwLengthOfInstallDirectory; i++)
{
sInstallDirectory[i] = sInstallDirectoryUNI[i];
}
sInstallDirectory[i++] = NULL;
AfxMessageBox(sInstallDirectory);
}
else
{
AfxMessageBox("Read Reg Entry Failed");
CErrorHandler Error1;
DWORD dwLastError;
dwLastError = GetLastError();
Error1.ResolveError(dwLastError);
}
Can anyone see a problem with this code its meant to read a value out of a string in teh registry and there is definately a value there. All this does though is display 3 random characters. The dword returns the right length of the string though.
Thanks for the help
Peter
TCHAR sInstallDirectory[MAX_PATH];
BYTE sInstallDirectoryUNI[MAX_PATH];
DWORD dwLengthOfInstallDirectory = NULL;
HKEY hUninstallInfo;
RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\RCAS\\UninstallInfo", 0, KEY_ALL_ACCESS, &hUninstallInfo);
if(RegQueryValueEx(hUninstallInfo, "InstallDirectory", NULL, NULL, &sInstallDirectoryUNI[0], &dwLengthOfInstallDirectory) == ERROR_SUCCESS)
{
TCHAR sTest[10];
ultoa(dwLengthOfInstallDirectory, sTest, 10);
AfxMessageBox(sTest);
for(int i = 0; i <= dwLengthOfInstallDirectory; i++)
{
sInstallDirectory[i] = sInstallDirectoryUNI[i];
}
sInstallDirectory[i++] = NULL;
AfxMessageBox(sInstallDirectory);
}
else
{
AfxMessageBox("Read Reg Entry Failed");
CErrorHandler Error1;
DWORD dwLastError;
dwLastError = GetLastError();
Error1.ResolveError(dwLastError);
}