Problem with the IShell_SetPrefs ! | developer.brewmp.com Problem with the IShell_SetPrefs ! | developer.brewmp.com

Developer

Problem with the IShell_SetPrefs !

Forums:

Hello everybody:

I have a big problem, i can´t store the state of the game, i need to store three char * and four int´s. I try to do that, storing an structure whose fields are the char *´s and int´s before said.
If i don´t make malloc, then i store the state always i never turn off the device. Otherwise, i lost the state.
If i make malloc for one char*, then i have that state permanently, but the first time that i turn on the device, then the aplication don´t recognize the stored state. And i can´t store another char*, why?, how could i store a state by storing one structure?

Well, very thanks! y hope to get response very soon :confused:

Atte. Alexandra Bustamante.

alexandra93 wrote:Hello everybody:
I have a big problem, i can´t store the state of the game, i need to store three char * and four int´s. I try to do that, storing an structure whose fields are the char *´s and int´s before said.
If i don´t make malloc, then i store the state always i never turn off the device. Otherwise, i lost the state.
If i make malloc for one char*, then i have that state permanently, but the first time that i turn on the device, then the aplication don´t recognize the stored state. And i can´t store another char*, why?, how could i store a state by storing one structure?Question is not quite clear. It would help if you post a code snippet here. In particulary your pref struct.
Did you check return value from ISHELL_SetPrefs(), are you using the right version and the right classid?
I always store preference's structure allocated on the heap. Doesn't mean it's necessary.
From what I understood you are trying to store preference's struct like this:
struct CPrefs
{
char * cp1;
char * cp2;
char * cp3;
int i1;
int i2;
int i3;
int i4;
;
...
CPrefs * pPrefs = new CPrefs;
// check if pPrefs was not NULL;
// fill in values
hrResult = ISHELL_SetPrefs(pApp->pShell, AEECLSID_YOURAPPCLSID, PREF_VERSION, pPrefs, sizeof(CPrefs));
// and later sometimes
CPrefs *pPreferences = new CPrefs;
// error checking...
hrResult = ISHELL_GetPrefs(pApp->pShell, AEECLSID_YOURAPPCLSID, PREF_VERSION, pPreferences, sizeof(CPrefs));
If you are actually storing strings, not just some char pointers - those strings would not be stored if you have something like I described above. However, that was just my guess, I don't know what you actually did, until you can provide a code snippet here. You need to declare the structure differently: struct CPrefs
{
char sz1[MAXSTRLEN1+1];
char sz2[MAXSTRLEN2+1];
char sz3[MAXSTRLEN3+1];
;
...
CPrefs * pPref = new CPrefs;
// ... error handling in case of NULL;
STRCPY(pPref->sz1, szString1);
STRCPY(pPref->sz2, szString2);
STRCPY(pPref->sz3, szString3);
...
hrResult = ISHELL_SetPrefs(pApp->pShell, AEECLSID_YOURAPPCLSID, PREF_VERSION, pPref, sizeof(CPrefs));
Also make sure you don't need AECHARs instead of chars. In which case you would, of course, need to use wide chars equivalents, such as WSTRCPY().
Debuggin hint:
You should check prefs.dat file in your brew directory (the 'top' directory where you have your .mif files). File is created or appended by ISHELL_SetPrefs(). Edit/view it with winhex or similar utility, to verify what was actually stored inside.
HTH

alexandra93 wrote:Hello everybody:
I have a big problem, i can´t store the state of the game, i need to store three char * and four int´s. I try to do that, storing an structure whose fields are the char *´s and int´s before said.
If i don´t make malloc, then i store the state always i never turn off the device. Otherwise, i lost the state.
If i make malloc for one char*, then i have that state permanently, but the first time that i turn on the device, then the aplication don´t recognize the stored state. And i can´t store another char*, why?, how could i store a state by storing one structure?Question is not quite clear. It would help if you post a code snippet here. In particulary your pref struct.
Did you check return value from ISHELL_SetPrefs(), are you using the right version and the right classid?
I always store preference's structure allocated on the heap. Doesn't mean it's necessary.
From what I understood you are trying to store preference's struct like this:
struct CPrefs
{
char * cp1;
char * cp2;
char * cp3;
int i1;
int i2;
int i3;
int i4;
;
...
CPrefs * pPrefs = new CPrefs;
// check if pPrefs was not NULL;
// fill in values
hrResult = ISHELL_SetPrefs(pApp->pShell, AEECLSID_YOURAPPCLSID, PREF_VERSION, pPrefs, sizeof(CPrefs));
// and later sometimes
CPrefs *pPreferences = new CPrefs;
// error checking...
hrResult = ISHELL_GetPrefs(pApp->pShell, AEECLSID_YOURAPPCLSID, PREF_VERSION, pPreferences, sizeof(CPrefs));
If you are actually storing strings, not just some char pointers - those strings would not be stored if you have something like I described above. However, that was just my guess, I don't know what you actually did, until you can provide a code snippet here. You need to declare the structure differently: struct CPrefs
{
char sz1[MAXSTRLEN1+1];
char sz2[MAXSTRLEN2+1];
char sz3[MAXSTRLEN3+1];
;
...
CPrefs * pPref = new CPrefs;
// ... error handling in case of NULL;
STRCPY(pPref->sz1, szString1);
STRCPY(pPref->sz2, szString2);
STRCPY(pPref->sz3, szString3);
...
hrResult = ISHELL_SetPrefs(pApp->pShell, AEECLSID_YOURAPPCLSID, PREF_VERSION, pPref, sizeof(CPrefs));
Also make sure you don't need AECHARs instead of chars. In which case you would, of course, need to use wide chars equivalents, such as WSTRCPY().
Debuggin hint:
You should check prefs.dat file in your brew directory (the 'top' directory where you have your .mif files). File is created or appended by ISHELL_SetPrefs(). Edit/view it with winhex or similar utility, to verify what was actually stored inside.
HTH