So I have been stuck on this for a while... thought I got it to work, but it breaks sometimes and I am not sure of the exact reasons...
I am not sure if this matters but I am writing this inside Browser Helper Object (BHO)... Is IE always 32 bit process, no matter whether it is running on 64 and 32 bit OS?
so I want to be able to read from registry, a key that I may need to crate...
I use this function:
if (RegCreateKeyEx(HKEY_CURRENT_USER, L"Software\\ProductName", 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS | KEY_WOW64_32KEY,
NULL, &hk, NULL) == ERROR_SUCCESS)
then I check if the key exist with this:
TCHAR ext_id[20];
DWORD toolbarIdLength;
if(RegQueryValueEx(hk, L"ext_id", NULL, NULL,
(LPBYTE)ext_id, &extIdLength) == ERROR_SUCCESS)
if successful then I make sure it is null terminated:
ext_id[extIdLength] = 0;
else I use wininet lib to send the info to my server, assigning new ext_id and I write to registry this value... using this function:
RegSetValueEx(hk, L"ext_id", 0, REG_SZ, (const BYTE *)ext_id, _tcslen(ext_id)*2 + 1);
for some weird reason it was writing only half of the stuff I was passing so I doubled _tcslen(ext_id) and added 1 for safety? Most of the examples I found online do not have that length multiplied by 2, it works for me like this so I left it alone...
seems all this worked properly:
and it worked for my dev_machine: Windows 7 64bit.
tested it on 32 bit Windows 7...
The issue came along on Windows XP IE 6, it did not work , but it seems that if I call RegQueryValueEx function again, it would return the correct value, so I noticed on the next request...
I also noticed that depending on what other string I send over to the server, it would work differently, it may be due to the fact that I am relatively new to C++, (only couple of weeks really in) and I am sure I am doing something really wrong.
Oh I read on msdn that I need to use KEY_WOW64_32KEY, or KEY_WOW64_64KEY, in the flags for opening the registry key depending on situation... but is this really necessary in my situation (BHO for browsers 6.0 to 8.0)