Funny symbols Reading Registry Key Values
-
I am writing a code in C++ to read out a Registry key Value. The program runs with no errors but instead of reading the value either shows nothing (in case value == 0) or shows funny face symbols :sigh: :omg: ;P (if value == 1 or other values). Once this value is read I would also need to assign it to a variable. Any solution would be highly appreaciated! ///// code ///// HKEY MyKey; unsigned long type=REG_SZ, size=1024; char res[1024]=""; RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\0", 0, KEY_READ, &MyKey); RegQueryValueEx (MyKey, "1400\0", NULL, &type, (LPBYTE)&res[0], &size); cout << "Ant the value is.....: " << *(LPBYTE)&res[0] << endl; RegCloseKey (MyKey); ///////////////////
-
I am writing a code in C++ to read out a Registry key Value. The program runs with no errors but instead of reading the value either shows nothing (in case value == 0) or shows funny face symbols :sigh: :omg: ;P (if value == 1 or other values). Once this value is read I would also need to assign it to a variable. Any solution would be highly appreaciated! ///// code ///// HKEY MyKey; unsigned long type=REG_SZ, size=1024; char res[1024]=""; RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\0", 0, KEY_READ, &MyKey); RegQueryValueEx (MyKey, "1400\0", NULL, &type, (LPBYTE)&res[0], &size); cout << "Ant the value is.....: " << *(LPBYTE)&res[0] << endl; RegCloseKey (MyKey); ///////////////////
Why are you unnecessarily adding
\0
to the string literals.J_E_D_I wrote:
RegQueryValueEx (MyKey, "1400\0", NULL, &type, (LPBYTE)&res[0], &size);
Why are you not reading this into a
DWORD
type?"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Why are you unnecessarily adding
\0
to the string literals.J_E_D_I wrote:
RegQueryValueEx (MyKey, "1400\0", NULL, &type, (LPBYTE)&res[0], &size);
Why are you not reading this into a
DWORD
type?"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
How the heck did you determine it should be a DWORD from that code??? I'm way more curious about the LPBYTE cast when displaying the "string"... Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Why are you unnecessarily adding
\0
to the string literals.J_E_D_I wrote:
RegQueryValueEx (MyKey, "1400\0", NULL, &type, (LPBYTE)&res[0], &size);
Why are you not reading this into a
DWORD
type?"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
Ahh now I see it (the DWORD) in the registry :rolleyes:
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Why are you unnecessarily adding
\0
to the string literals.J_E_D_I wrote:
RegQueryValueEx (MyKey, "1400\0", NULL, &type, (LPBYTE)&res[0], &size);
Why are you not reading this into a
DWORD
type?"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
(I swear yesterday I saw my message succesfully posted on the website, but today I can't find it anymore! So I'm posting it again). David, I followed your advice and tried to read it into a DWORD type, but still it doesn't seem to work. What am I doing wrong? Besides reading the registry value, I need to assign it to a variable. Help please! HKEY MyKey; DWORD dwLen = sizeof(DWORD); DWORD dwKeyEn = 0; RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3", 0, KEY_READ, &MyKey); RegQueryValueEx(hKey, "1400", NULL, NULL,(LPBYTE)&KeyEn, &dwLen); cout << "And the value is.....: " << *(LPBYTE)&KeyEn << endl; RegCloseKey (MyKey);
-
(I swear yesterday I saw my message succesfully posted on the website, but today I can't find it anymore! So I'm posting it again). David, I followed your advice and tried to read it into a DWORD type, but still it doesn't seem to work. What am I doing wrong? Besides reading the registry value, I need to assign it to a variable. Help please! HKEY MyKey; DWORD dwLen = sizeof(DWORD); DWORD dwKeyEn = 0; RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3", 0, KEY_READ, &MyKey); RegQueryValueEx(hKey, "1400", NULL, NULL,(LPBYTE)&KeyEn, &dwLen); cout << "And the value is.....: " << *(LPBYTE)&KeyEn << endl; RegCloseKey (MyKey);
J_E_D_I wrote:
(I swear yesterday I saw my message succesfully posted on the website, but today I can't find it anymore! So I'm posting it again).
The search feature is sometimes cantankerous.
J_E_D_I wrote:
RegQueryValueEx(hKey, "1400", NULL, NULL,(LPBYTE)&KeyEn, &dwLen); cout << "And the value is.....: " << *(LPBYTE)&KeyEn << endl;
Should probably be:
RegQueryValueEx(hKey, "1400", NULL, NULL, (LPBYTE)&dwKeyEn, &dwLen);
cout << "And the value is.....: " << dwKeyEn << endl;"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
J_E_D_I wrote:
(I swear yesterday I saw my message succesfully posted on the website, but today I can't find it anymore! So I'm posting it again).
The search feature is sometimes cantankerous.
J_E_D_I wrote:
RegQueryValueEx(hKey, "1400", NULL, NULL,(LPBYTE)&KeyEn, &dwLen); cout << "And the value is.....: " << *(LPBYTE)&KeyEn << endl;
Should probably be:
RegQueryValueEx(hKey, "1400", NULL, NULL, (LPBYTE)&dwKeyEn, &dwLen);
cout << "And the value is.....: " << dwKeyEn << endl;"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
With your modifications it doesn't show the funny symbols anymore..but it always returns "0" (as defined above by "DWORD dwKeyEn = 0", I guess) rather than reading the actual value from the registry. :~
So does HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1400 actually exist, and does it have a non-zero value? I tried this on my machine and it worked fine. You might verify that the last argument to
RegOpenKeyEx()
and the first argument toRegQueryValueEx()
have the same value."Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
So does HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1400 actually exist, and does it have a non-zero value? I tried this on my machine and it worked fine. You might verify that the last argument to
RegOpenKeyEx()
and the first argument toRegQueryValueEx()
have the same value."Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne