PocketMatrix forums

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

Weird DrawText error

Has anyone experienced the same thing in using DrawText? My DrawText keeps on displaying every other character from my string. I've posted the code below. "name1" is supposed to have 8 bytes length.

Code:

TCHAR name1[9]; //global declaration of name1

//cut from a function that reads name1 from file
FILE *fp = _tfopen(GetPath(TEXT("scores.dat")), TEXT("r"));
if(fp == NULL) return;

fread(name1, 8, 1, fp);

//cut from a function that displays name1
surface.DrawText(100, 118, name1, &m_font, GDDRAWTEXT_LEFT, NULL, NULL);


If name1 in my file is "Erick", the code above outputs "Eik". Has anyone encountered this? Any workarounds?
My only guess is that the file is in multichar format and you are running the code on the Pocket PC (unicode format). Have you tried running the code on a stationary computer and looked into the string using the debugger?
Yes its working great on my PC but when compiled and run on a PPC, it doesn't. How do I convert the file to a non multichar format?
Yep the error only shows on the PPC. I simply wanted to drawtext the strings that I've read from the file? How will I modify my code above?

Thanks in advance,

Erick :-)
I'm posting new code to give you a better picture of what my problem is. Actually, I couldn't figure out if the problem lies on my "read file" or the drawtext function. :-)

Code:

//my declarations
TCHAR name1[9],
name2[9],
name3[9],
name4[9],
name5[9],
score1[9],
score2[9],
score3[9],
score4[9],
score5[9];

//create temporary file
void CreateScoresFile()
{
#ifdef _WIN32_WCE
FILE *fp = _wfopen(GetPath(TEXT("scores.dat")), TEXT("w"));
#else
FILE *fp = fopen(GetPath(TEXT("scores.dat")), TEXT("w"));
#endif
if(fp == NULL) return;

fprintf(fp, "%s", " NAME 500 NAME15 400 NAME5 300 OK 200 NAME32 100");
fclose(fp);
}

//function to read data from created file
void ReadScoresFromFile()
{
#ifdef _WIN32_WCE
FILE *fp = _wfopen(GetPath(TEXT("scores.dat")), TEXT("r"));
#else
FILE *fp = fopen(GetPath(TEXT("scores.dat")), TEXT("r"));
#endif
if(fp == NULL) return;

fread(name1, sizeof(name1) - 1, 1, fp);
fread(score1, sizeof(score1) - 1, 1, fp);
fread(name2, sizeof(name2) - 1, 1, fp);
fread(score2, sizeof(score2) - 1, 1, fp);
fread(name3, sizeof(name3) - 1, 1, fp);
fread(score3, sizeof(score3) - 1, 1, fp);
fread(name4, sizeof(name4) - 1, 1, fp);
fread(score4, sizeof(score4) - 1, 1, fp);
fread(name5, sizeof(name5) - 1, 1, fp);
fread(score5, sizeof(score5) - 1, 1, fp);

fclose(fp);
}

//draw data read from file on screen
HRESULT CMyApplication::ProcessNextFrame(CGapiSurface& surface, DWORD dwFlags)
{
surface.DrawText(160, 118, name1, &m_font, GDDRAWTEXT_RIGHT, NULL, NULL);
surface.DrawText(222, 118, score1, &m_font, GDDRAWTEXT_RIGHT, NULL, NULL);
surface.DrawText(160, 140, name2, &m_font, GDDRAWTEXT_RIGHT, NULL, NULL);
surface.DrawText(222, 140, score2, &m_font, GDDRAWTEXT_RIGHT, NULL, NULL);
surface.DrawText(160, 162, name3, &m_font, GDDRAWTEXT_RIGHT, NULL, NULL);
surface.DrawText(222, 162, score3, &m_font, GDDRAWTEXT_RIGHT, NULL, NULL);
surface.DrawText(160, 184, name4, &m_font, GDDRAWTEXT_RIGHT, NULL, NULL);
surface.DrawText(222, 184, score4, &m_font, GDDRAWTEXT_RIGHT, NULL, NULL);
surface.DrawText(160, 206, name5, &m_font, GDDRAWTEXT_RIGHT, NULL, NULL);
surface.DrawText(222, 206, score5, &m_font, GDDRAWTEXT_RIGHT, NULL, NULL);

return S_OK;
}


In the first "name" example, the data displayed by DrawText on my PPC would only be "NM" instead of "NAME". On the PC however, it works great.
I called CreateScoresFile() then ReadScoresFromFile() upon the game's initialization. Is there something wrong with my code? Help please? :-)