Windows CE: Outputting Copyrts.txt to the Debug Port
 Someone asked on the newsgroups recently about reading copyrts.txt from an application. This is really a simple task to do, but I decided to output the file to the debug port, which turned out to be way more interesting.
The code below works to read the file into a buffer that is allocated to be the size of the file, so it reads the entire file in one call to ReadFile(). Of course to keep this simple, I left out any and all error handling – which is really dangerous in this code, so be sure to add it. It also successfully outputs the file using strtok() and RETAILMSG(). Notice that it uses a capital S, not lower case. The capital S is used to tell RETAILMSG() that the string is a char array instead of multi byte.
void ReadCopyrights()
      HANDLE hFile;
      DWORD FileSize;
      char *FileData;
      DWORD NumBytesRead;
      hFile = CreateFile (TEXT("\\Windows\\Copyrts.txt"),        
      FileSize = GetFileSize (hFile, NULL) ;
      FileData = (char *)malloc( FileSize );
      char *pStr = FileData;
      strtok(pStr, "\n\0");
      while( pStr != NULL )
            RETAILMSG(1, (TEXT("%S\n"), pStr ));
            pStr = strtok(NULL, "\n\0");
      free( FileData );
My first attempt simply called RETAILMSG( 1, (TEXT(“%S”), FileData )); but I found that it didn’t output the entire file contents. Honestly, I don’t know why, maybe some restriction on the string length that it works with. My next attempt output one character at a time, but that seemed slow and messy.
Copyright © 2009 – Bruce Eitman
All Rights Reserved