File I/O

I'm trying to use file I/O functions to log debugging statements that I can view on the handheld. The code I got from msdn seems to do the trick except when I open the file on the handheld, PocketWord only displays the first character I write to the file. If I copy the file to the desktop, everything I wrote to the file appears as it should. My code for all of my file I/O is as follows:

BOOL LogStartup (void)

{

HANDLE file;

TCHAR szFileName [MAX_PATH];

memset (szFileName, 0, MAX_PATH * 2);

wcscpy (szFileName, TEXT ("\\folder\\logfile.txt"));

file = CreateFile (szFileName, GENERIC_WRITE, FILE_SHARE_WRITE,

NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL);

LogFileHandle = file;

return TRUE;

}

BOOL LogClose (void)

{

CloseHandle (LogFileHandle);

return TRUE;

}

int LogWrite (TCHAR *szError)

{

DWORD BytesWritten = 0;

int len = wcslen (szError);

if (!WriteFile (LogFileHandle, szError, len * 2, &BytesWritten, NULL))

ErrorExit (hWnd, TEXT ("WriteFile"));

return BytesWritten;

}

Where ErrorExit is a function with GetLastError and MessageBox(), and LogFileHandle is a global.



Answer this question

File I/O

  • Bhushan Akole

    Hi Mish,

    I am facing the same problem which u had faced earlier while using Writefile() to write data in a .txt file of PDA.

    I am trying to save the data(read tags) which is in the form of string in a file. I can save the data in the file but cant see all the charachters except 1st, when the file is opened in Pocketword on PDA . I downloaded the file on PC and can open read the data in wordpad/notepad/excel.

    I read your opinion that char * works as Pocketword doesnt support w_char and added this new code but still no difference. Please rectify my code below.

    static unsigned short Buffer[1000] = {0}; // unicode buffer
    unsigned short *pwc = &Buffer[1000];

    LPSTR BytePtr;
    char c,tagWrc[512] = {0};

    BytePtr = (LPSTR)pwc;

    leng = wcslen(pwc);
    for(int z=0;z<=leng;z++)
    {
    tagWrc[Z] = *BytePtr++;
    }

    TagWrite(tagWrc);

    My received data is in Buffer and this data is to be saved in a file.

    where Tag write is the function used to write the data in a file on PDA.

    Thanks,

    Eshani


  • Charles W

    w_chare stands for wide char for Unicode support :)

  • robincurry

    Perhaps it's a Unicode issue If one system were unicode and the other were not then your data would look like 0x410x00. Whomever is not unicode would stop at the first 0x00 because they would interpret this as a null terminating character.
    Hope this helps.

  • TheMilkMan

    I've considered this. I wrap all my buffers in TEXT (), and doesnt seem to have an effect. Maybe pocketword doesnt support unicode I'll try using straight char*, thanks the for suggestion.
  • Mr Big

    Using char* did the trick. PocketWord on CE doesn't support w_char. ... Kind of ironic.
  • File I/O