PocketMatrix forums

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

Font::drawf

Hi Guys,

The following code causes an exception 0xc0000005 on an actual device, and yet it works just fine when I run it on the PC in visual studio. Any idea what's going on here?

Code:

char Name[15] = "Test";

#if defined(_WIN32_WCE)
m_Font.drawf(pDisplay, x_loc, y_loc, FONT_LEFT, (wchar_t *)Name);
#else
m_Font.drawf(pDisplay, x_loc, y_loc, FONT_LEFT, (char *)Name);
#endif
rather than try to solve this can I suggest that you do your text a different way to avoid having to do the 'IFDEF' stuff. I have been through all of this so I know what I'm doing (I don't say that very often :) )

use TCHAR and the _t macros throughout. A few sample code lines (I can provide many more).keystr is defined as TCHAR [nn]

m_font.draw(display,109,239, FONT_LEFT,TEXT("V"));

LoadString(_Module.GetResourceInstance(),IDS_GUILD2A,keystr,26);
m_font.draw(display,120, 30, FONT_CENTER, keystr);

_itot(bases[cur_base].trade[z+16].cost,keystr,10);
m_font.draw(display,200,110+(12*z), FONT_RIGHT,keystr);
simonjacobs · 15 Jul 2004, 11:10 UTC
Is it because you are declaring the text as 'char' and then telling windows ce it is wchar with a cast, which is not true?

Doing a cast like (wchar_t*)name doesnt CONVERT the string to wide char, it just tells the compiler that name is a pointer to that type, which in this case it isnt.

Simon
Thanks Conan/Simon...I appreciate your suggestions. I'll give them a try and see if it fixes the problem.
Conan,

I tried your suggestions, but I'm still getting the illegal exception on my DELL Axim. Here's my code:

Code:

TCHAR Name[15];

strcpy ((char *)Name, "Test");
m_Font.draw(pDisplay, 10, 10, FONT_LEFT, (wchar_t *)Name);


Can you please provide some examples for loading TCHAR array with a string and then passing to 'draw' function? Thanks! :)
Try _tstrcpy.
No problem, you just need to use the _t variants of all the normal functions. If you look at the help within evc3 for each regular function you will see the _t version referenced. This approach makes everything work on big PC VC and on PPC evc.

eg:-
Code:
_tcsncpy(keystr,systems[this_system].name,20);

_tcscat(keystr,TEXT(" ONE"));

_tcsncpy(keystr,TEXT("holds: "),8);

_tcscat(keystr,txttemp1);



simonjacobs · 16 Jul 2004, 10:07 UTC
You should note that the crash in your second example is from the same cause as the crash in your first example: incorrect use of a cast.

You should be careful when casting the type of a variable to another type, only use it if you know what you are doing. Casting the type tells the compiler the variable is a different type than it previously thought WITHOUT CONVERTING IT. You are telling the compiler you are sure the variable is a different type already. Only do it if you are sure it is, not just because it seems to fix compile errors (but then crashes the machine!).
Thanks guys! That did the trick...everything is working now! :D