Index: base/applications/calc/winmain.c =================================================================== --- base/applications/calc/winmain.c (revision 61539) +++ base/applications/calc/winmain.c (working copy) @@ -231,6 +231,24 @@ HKEY hKey; #endif +#if _WIN32_WINNT >= 0x0500 + if (RegOpenKeyEx(HKEY_CURRENT_USER, + TEXT("SOFTWARE\\Microsoft\\Calc"), + 0, + KEY_QUERY_VALUE, + &hKey) == ERROR_SUCCESS) { + /* Try to load last selected layout */ + tmp = _tcslen(buf) * sizeof(calc.layout); + RegQueryValueEx(hKey, TEXT("layout"), NULL, NULL, (LPBYTE)calc.layout, &tmp); + + /* Try to load last selected formatting option */ + tmp = _tcslen(buf) * sizeof(calc.usesep); + RegQueryValueEx(hKey, TEXT("UseSep"), NULL, NULL, (LPBYTE)calc.usesep, &tmp); + + /* close the key */ + RegCloseKey(hKey); + } +#else /* Try to load last selected layout */ GetProfileString(TEXT("SciCalc"), TEXT("layout"), TEXT("0"), buf, SIZEOF(buf)); if (_stscanf(buf, TEXT("%lu"), &calc.layout) != 1) @@ -242,6 +260,7 @@ calc.usesep = FALSE; else calc.usesep = (tmp == 1) ? TRUE : FALSE; +#endif /* memory is empty at startup */ calc.is_memory = FALSE; @@ -258,10 +277,10 @@ KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) { /* get these values (ignore errors) */ - tmp = sizeof(calc.sDecimal); + tmp = _tcslen(buf) * sizeof(calc.sDecimal); RegQueryValueEx(hKey, TEXT("sDecimal"), NULL, NULL, (LPBYTE)calc.sDecimal, &tmp); - tmp = sizeof(calc.sThousand); + tmp = _tcslen(buf) * sizeof(calc.sThousand); RegQueryValueEx(hKey, TEXT("sThousand"), NULL, NULL, (LPBYTE)calc.sThousand, &tmp); /* close the key */ @@ -287,10 +306,29 @@ static void save_config(void) { TCHAR buf[32]; +#if _WIN32_WINNT >= 0x0500 + HKEY hKey; + if (RegOpenKeyEx(HKEY_CURRENT_USER, + TEXT("SOFTWARE\\Microsoft\\Calc"), + 0, + KEY_ALL_ACCESS, + &hKey) == ERROR_SUCCESS ) { + LPTSTR sepValue = (calc.usesep == TRUE) ? TEXT("1") : TEXT("0"); + + _stprintf(buf, TEXT("%lu"), calc.layout); + + /* PROBLEM COMES FROM HERE */ + RegSetValueEx(hKey, TEXT("layout"), 0, REG_DWORD, (LPBYTE)calc.layout, sizeof(DWORD)); + RegSetValueEx(hKey, TEXT("UseSep"), 0, REG_DWORD, (LPBYTE)sepValue, _tcslen(sepValue) * sizeof(TCHAR)); + + RegCloseKey(hKey); + } +#else _stprintf(buf, TEXT("%lu"), calc.layout); WriteProfileString(TEXT("SciCalc"), TEXT("layout"), buf); WriteProfileString(TEXT("SciCalc"), TEXT("UseSep"), (calc.usesep==TRUE) ? TEXT("1") : TEXT("0")); +#endif } static LRESULT post_key_press(LPARAM lParam, WORD idc)