PocketMatrix forums

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

Getting the current directory in windows CE

Someone suggested I should use this:

TCHAR junk[50];
GetModuleFileName( NULL, junk, 50 );

I had it write out to a file for testing and it just said the path was "\".

I was wondering if maybe I did this wrong, or if theres a different way of doing it.
Windows CE uses unicode. What were you viewing your output file with?

Dan East
I tried word, and then notepad.

TCHAR junk[50];
GetModuleFileName( NULL, junk, 50 );
FILE *input;
input=fopen("error.txt","w");
fprintf(input,"%s",junk);
fclose(input);

That exact code there outputs to error.txt a "\" and thats it....
Okay, Windows CE uses UNICODE for almost all system calls. Thus TCHAR / WCHAR types are not chars, but shorts. Each character is represented by two bytes. For english, the second byte is always a zero. Thus if you try to use a UNICODE string with an ANSI / ASCII function, it will think the string is only one character in length. fprintf is not a UNICODE function. The quickest fix would be:
Code:

TCHAR junk[50];
GetModuleFileName( NULL, junk, 50 );
FILE *input;
input=fopen("error.txt","w");
fwrite(junk, 2, _tcslen(junk), input);
fclose(input);


Dan East