PocketMatrix forums

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

CGapiSurface::DrawText

Hi.

While compiling for the ppc2002em I am getting strange error:
error C2664: 'long __thiscall CGapiSurface::DrawTextW(unsigned long,unsigned long,const unsigned short *,class CGapiBitmapFont *,unsigned long,struct _GDTEXTFX *,unsigned long *)' : cannot conv
ert parameter 3 from 'const char *' to 'const unsigned short *'

Basically, for some reason my call to DrawText(..)
ends up calling some sort of internal DrawTextW function which has a different signature than CGapiSurface::DrawText(..) method.
If I comment out the code that calls DrawText everything compiles and runs on the emulator fine.

Any suggestions what is going here ?

Thanks

Walter
Hi Walter,

"cannot convert parameter 3 from 'const char *' to 'const unsigned short *'"

The problem is with your text strings. Basically, Visual C++ (and Embedded Visual C++) supports three different types of strings: multichar (8-bit), unicode (16-bit) and automatic (8-bit or 16-bit depending on platform).

GapiDraw uses the automatic string width (8-bit or 16-bit strings) which are stored in a format known as TCHAR. A TCHAR is 8-bit on stationary PCs, and 16-bit on Pocket PCs. To store TCHAR strings in the file's resource area you have to use a macro to assign the string. Basically you do this as:

const TCHAR* pStr = TEXT("My string");
or
const TCHAR* pStr = _T("My string");

Microsoft usually likes to define their strings as LPCTSTR (long pointer, constant T-string):

LPCTSTR pStr = _T("My string")

Basically LPCTSTR is defined as "const TCHAR*"

So. How do you use all this? Just write "TEXT" or "_T" around all your strings and your set:

mysurface.DrawText(dwX, dwY, TEXT("The string"), ...);

If you omit the TEXT("") macro, the string will be stored as an 8-bit string, where DrawText expects a 16-bit unicode string on the PocketPC.

/Johan
Thanks a lot.

I haven't touched Win32 platform for about 6 years (before MFC ) and uh .. things have changed since then a lot.

At least WinMain stayed the same...

Anyway, thanks for the answer :-)
But what do you do if you're using a variable?

Instead of...

surface.DrawText(dwX, dwY, TEXT("hi!")...

should it be just...

TCHAR mystring;
surface.DrawText(dwX, dwY, mystring...

And then what if...

char mystring;
...how do I convert it to TCHAR for me to be able to use it in DrawText?

Am I doing it right? :-)
egarayblas: There are some C calls (MultiByteToUniCode or something, don't remember) that converts text from one format to the other.

Regarding your issue: It's probably best to have your score file in one format (e.g. unicode), read the score file into a WCHAR array, and then convert that into multibyte if not _UNICODE is defined.