RegQueryValueEx 32/64 bit Irregularity

Hope someone can help me here. I have a function which reads the windows registry below - this works perfectly when it's called from a 64 bit application called MetaTrader 5 but when it's recompiled for the 32 bit version of MetaTrader 5 (using the /x86 switch in the SDK 7.1 it doesn't work when called from the 32 bit app?

This is doing my head in!

Here's the code..

By the way - rgValue is declared as 'char rgValue[1024];' as a global variable in the declarations at the start of the program. The section below is just the function which queries the registry.

void RR(string key)
{

HKEY keyHandle;
//char rgValue [1024];
//char fnlRes [1024];
DWORD size1;
DWORD Type;
LPSTR keyp = &key[0];
if( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
"Software\\FXAlgoTrader",0,
KEY_QUERY_VALUE, &keyHandle) == ERROR_SUCCESS)
{
size1=1023;
RegQueryValueEx( keyHandle, keyp, NULL, &Type,
(LPBYTE)rgValue,&size1);
//char Ret_Val=
//MessageBox(NULL, rgValue, (keyp), MB_SYSTEMMODAL|MB_ICONINFORMATION);
string Val=Proc(rgValue);

const char * Val_c=Val.c_str();
sprintf_s(fnlRes,Val_c);
//MessageBox(NULL, fnlRes, ("Registry="), MB_SYSTEMMODAL|MB_ICONINFORMATION);
}
else strcpy_s(fnlRes,"Couldn't access system information!");

RegCloseKey(keyHandle);
return;
}
On 64-bit Windows the 32-bit SOFTWARE registry hive is remapped to the following.
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node

So to read the 64-bit hive from a 32-bit app you need to change KEY_QUERY_VALUE to KEY_QUERY_VALUE | KEY_WOW64_64KEY in the call to ReqOpenKeyEx
Topic archived. No new replies allowed.