Question

I have a handheld device running WM6.5 and trying to put together an application that should prompt the user for some information (login, password) and save it to a file for later use.

Have tried app.config files but unfortunately it requires System::Configuration, I can add the DLL but can't get the code to run, it requires CRL or something like that which I can't configure this being a mobile app - the required option is missing from the project/solution configuration section.

I am using Visual Studio 2008 C++

What's the best way to make this happen? Precisely, 1) write a string somewhere and 2) read it back later on.

TIA

Later edit:

I have tried using a binary file, like this

// write to config file
std::string s="helloworldhelloworldhelloworld";
ofstream ofile("test.txt",ios::binary);
ofile.write((char*)s.c_str(),strlen(s.c_str()));
ofile.close();

And then I have tried reading it back like this

// read config file
char read_str[60];
ifstream inf("test.txt",ios::binary);
inf.read(read_str,60);    
inf.close();

LPCTSTR application_settings = CA2W(read_str);

What happens is it adds some garbage at the end of the string, if the string is longer less garbage, otherwise more.

Is there a way to sort out this conversion issue?

Was it helpful?

Solution

Turns out, project was using Unicode and had to use wifstream and wofstream to be able to properly read the strings, rather than attempt to convert them from ANSI to unicode.

This should be a reminder for me to stay away from strong typed languages in the future. Too bad there's no other significant choice for Windows Mobile. Spent a bunch of hours on this, I could have used that time for something else.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top