PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

String resource problems

Hi,
I'm trying to utilize string resources in a project I'm doing using GapiDraw.

If I define an entry in the string table like this:
NAME:IDS_STRING
VALUE:1
CAPTION:Line 1\nLine 2\nLine 3\n

Since I don't own a pocket PC yet I'm using the window ce pocket pc emulator (could this be the problem?)
Then if I run the following code withing createsurfaces:
Code:

TCHAR buffer[1000];
::LoadString(hInstance,1,buffer,1000);
FILE *file;
file = _tfopen(TEXT("file.txt"),TEXT("at"));
fwrite(buffer,sizeof(TCHAR),_tcslen(buffer),file);
fclose(file);

Then if I use the windows ce remote file viewer and transfer file.txt to my computer and open it it looks like this where _ is a space

L_i_n_e___1_
_L_i_n_e___2_
_L_i_n_e___3_

There seems to be spaces between every character of the original resource string. Is this something to do with the TCHAR stuff or is it a flaw in the emulator?

The main reason is eventually I want to tokenize the resource string with _tcstok but when I tried doing that it failed miserably with the token TEXT('\n') and TEXT("\n").

Any advice on how to change things? Or is this just the standard functionality for string resources. Am I using ::LoadString incorrectly?

Thanks for any assistance,

CM
Pejo Software - Per · 07 Feb 2003, 08:04 UTC
The problem is that you write wide characters to your file and that probably isn't what you want (At least it isn't what your editor on the PC want).
You need to convert the string to normal characters before passing it to fwrite.
You could do something like:
#ifdef _UNICODE
wcstombs(..........
#else
or there might be some _t function you can use.
fwrite doesnt give a crap what data you are writing as long as the size and buffer are correct, which they appear to be. What you are seeing is unicode in an editor that doesn't apparently support unicode viewing. What editor are you viewing the file in?

Depending on what you want to happen, either get a unicode editor to read your files, or use some other method to store your string. Since PPC are pretty much all unicode, I couldn't tell you how to store non-unicode strings in your string table. But something like this will work:
Code:

char * myNonUnicodeString = "blarg blargful blargy";

Then:
Code:

FILE *file;
file = _tfopen(TEXT("file.txt"),TEXT("at"));
fwrite(myNonUnicodeString, sizeof(char), strlen(myNonUnicodeString), file);
fclose(file);


Of course you can store your string and copy it into a buffer or whatever. I'm pretty sure if you use fopen with char strings it will fail to find your file, but my memory may have failed me.
fopen works with (and requires) ANSI char strings. _wfopen and _tfopen (when UNICODE is defined for the latter) work with wide chars.

Dan East
Dan East wrote:
fopen works with (and requires) ANSI char strings. _wfopen and _tfopen (when UNICODE is defined for the latter) work with wide chars.


Yeah, but will fopen("File.txt"... open the file "File.txt" on your pda?
Yes.

Dan East
Conan · 08 Feb 2003, 08:51 UTC — where to define UNICODE in VC6 ?
I can't find a single example or help text saying where to define UNICODE nor any related stuff, eg: is _UNICODE also needed & if UNICODE is defined will TCHAR just work as wide ?

(currently trying to get my project working in VC6 but it's full of string tables which are wide chars & I'm currently using TCHAR in places. I've read the existing PF threads but can't see an example stating where to set up #define UNICODE

( ps: The demo version of PocketGL does file handling for both PC & PPC using defines if that's of any help. It's available on PocketGear )
UNICODE is defined in your Project Settings, C/C++ tab. UNICODE must be defined for Windows CE builds. All of the WIN32 API routines only exist in UNICODE format, and it is almost a certainty that your application will at least call one of those routines (CreateWindow, etc). The Windows NT family supports both ANSI and UNICODE. The Windows 95 family only supports ANSI, and Windows CE only supports UNICODE.

Dan East
Conan · 08 Feb 2003, 19:13 UTC — error once UNICODE defined
Thanks Dan, I found where the settings go so now all my errors due to TCHAR etc go away. Now I'm left with the one error:-
Building my PocketFrog project in VC6 (which builds fine in eVC) with UNICODE & _UNICODE defined I get the error
C:\Windows CE Tools\frog\PocketFrog_0_6_0\SAMPLES\rotate\rotate.cpp(146) : error C2731: 'WinMain' : function cannot be overloaded
C:\Windows CE Tools\frog\PocketFrog_0_6_0\SAMPLES\rotate\rotate.cpp(145) : see declaration of 'WinMain'

so I guess the compiler thinks that one of the parameters for winmain has changed and this must be due to UNICODE causing param 3 LPTSTR to have a different definition ? or less likely param 4 int

Can anyone assist with this problem ?