Hi Everybody,
I just recently tried my software on a WM2005 device, and I'm finding that my code for writing/reading the windows registry isn't working.
I basically save off game state info when exiting the game, and I restore the state from the registry when the game is started. However, the game state is totally corrupted on a restart.
This code works perfectly on 2002/2003 devices. Any ideas what could be different about WM2005 in regards to the registry? Any help would be greatly appreciated!
Here's some of my code:
I just recently tried my software on a WM2005 device, and I'm finding that my code for writing/reading the windows registry isn't working.
I basically save off game state info when exiting the game, and I restore the state from the registry when the game is started. However, the game state is totally corrupted on a restart.
This code works perfectly on 2002/2003 devices. Any ideas what could be different about WM2005 in regards to the registry? Any help would be greatly appreciated!
Here's some of my code:
- Code:
typedef struct {
int pieces[90];
int GameType;
} PreferenceType;
- Code:
void MyGame::SavePrefs ()
{
HKEY pref_key ;
PreferenceType saveprefs;
int i;
for (i=0; i<90; i++) {
saveprefs.pieces[i] = pieces[i];
}
saveprefs.GameType = GameType;
RegCreateKeyEx (HKEY_LOCAL_MACHINE, TEXT ("Software\\MyGame"), 0, NULL, 0, 0, NULL, &pref_key, &tmp) ;
// Write registry struct
RegSetValueEx (pref_key, TEXT ("Data"), 0, REG_BINARY, (LPBYTE) &saveprefs, sizeof (saveprefs)) ;
RegCloseKey (pref_key) ;
return ;
}
- Code:
void MyGame::LoadPrefs ()
{
HKEY pref_key;
DWORD tmp1, tmp2;
PreferenceType loadprefs;
int i=0;
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, TEXT ("Software\\MyGame"), 0, 0, &pref_key) != ERROR_SUCCESS) {
return ;
}
// Load preferences struct
RegQueryValueEx (pref_key, TEXT ("Data"), NULL, &tmp1, (LPBYTE) &loadprefs, &tmp2) ;
for (i=0; i<90; i++) {
pieces[i] = loadprefs.pieces[i];
}
GameType = loadprefs.GameType;
RegCloseKey (pref_key);
return ;
}
- Code:
bool MyGame::GameInit()
{
HKEY pref_key ;
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, TEXT ("Software\\MyGame"), 0, 0, &pref_key) == ERROR_SUCCESS) {
// Preferences already exist
RegCloseKey (pref_key) ;
LoadPrefs() ;
}
}