I have spent the past 5 hours trying to solve this problem, so I'm hoping that someone can help me.
I have a struct defined for the data that I want to load/save to the registry. For example, I have the following data for my high score data (score and player name):
I can save/load the score (integer) data with no problems. But, when I try to load the TCHAR (string) data, I either get garbage or I get a fatal exception.
Here's my code to save the data to registry:
And, here's my code to load the data from the registry:
Once again, the integer data (Score) loads perfectly. It's the TCHAR (string) data for the player's name that is causing the problems.
I've spent way too much time on this already, so any help would be greatly appreciated!
Thanks...

I have a struct defined for the data that I want to load/save to the registry. For example, I have the following data for my high score data (score and player name):
- Code:
typedef struct {
int Player1_Score;
int Player2_Score;
...
TCHAR Player1_Name[20];
TCHAR Player2_Name[20];
...
} RegistryData;
I can save/load the score (integer) data with no problems. But, when I try to load the TCHAR (string) data, I either get garbage or I get a fatal exception.
Here's my code to save the data to registry:
- Code:
RegistryData saveprefs;
saveprefs.Player1_Score = Player1_Score;
saveprefs.Player2_Score = Player2_Score;
...
_tcsncpy(saveprefs.Player1_Name, Player1_Name, _tcslen((TCHAR *)Player1_Name));
_tcsncpy(saveprefs.Player2_Name, Player2_Name, _tcslen((TCHAR *)Player2_Name));
...
And, here's my code to load the data from the registry:
- Code:
RegistryData loadprefs;
Player1_Score = loadprefs.Player1_Score;
Player2_Score = loadprefs.Player2_Score;
...
_tcsncpy(Player1_Name, loadprefs.Player1_Name, _tcslen((TCHAR *)loadprefs.Player1_Name));
_tcsncpy(Player2_Name, loadprefs.Player2_Name, _tcslen((TCHAR *)loadprefs.Player2_Name));
...
Once again, the integer data (Score) loads perfectly. It's the TCHAR (string) data for the player's name that is causing the problems.
I've spent way too much time on this already, so any help would be greatly appreciated!
Thanks...