What you are doing is saving the *pointer* to the preference data, which is 
of course not what you want as that pointer is invalid as soon as you call 
MemPtrFree.  To save the database, you would do the following:

MyPrefDB *prefP = (MyDB *) MemPtrNew (sizeof(MyPrefDB));
// populate data here before you save it
PrefSetAppPreferences(kCreator, 0, 1, &prefP, sizeof(MyPrefDB), true);
MemPtrFree(prefP);

and to restore:

UInt16 PrefSize = sizeof(MyPrefDB);
MyPrefDB *prefP = (MyPrefDB *) MemPtrNew (sizeof(MyPrefDB));
PrefGetAppPreferences(kCreator, 0, &prefP, &PrefSize, true);

when you are done accesing the data, use MemPtrFree to release it.

Also, the call PrefGetAppPreferences will return values which will let you 
know what's going wrong.  If there's no preference stored, then it'll tell 
you.  It also returns the size of the preference data.  Read the 
documentation on that function if you want a better understanding of what it 
tells you.

Hope this helps, and hope I didn't make any typos.  :)
--
Tim Kostka



<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Problem: How do I retrieve a large struct Preference which was stored by 
> using MemPtrNew??
>
> I was able to set the preference in my StopApp function this way:
>
> MyPrefDB *prefP = (MyDB *) MemPtrNew (sizeof(MyPrefDB));
> PrefSetAppPreferences(kCreator, 0, 1, prefP, sizeof(prefP), true);
> MemPtrFree(prefP);
>
> In my startApp function, I try to retrieve it using this code, but its 
> giving me an error:
>
> UInt16 PrefSize = sizeof(MyPrefDB);
> MyPrefDB *prefP = (MyPrefDB *) MemPtrNew (sizeof(MyPrefDB));
> PrefGetAppPreferences(kCreator, 0, prefP, &PrefSize, true);
> MemPtrFree(prefP);
>
> Am I doing this right?? Any help in this matter is greatly 
> appreciated..Thanks in advance.
>
> 



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to