Listing 2

DWORD WINAPI ResponseThreadProc(LPVOID lpParam) {
  HANDLE hTermEvt = (HANDLE)lpParam;
  WIN32_FIND_DATA findFileData;
  HANDLE hFind;
  try {
    XMLPlatformUtils::Initialize();
  }
  catch(const XMLException& e) {
    return -1;
  }
  char szFileURL[128];
  char szFilename[128];
  char szBasePath[32];
  strcpy(szBasePath, "checkin\\response");
  while ( true ) {
    // Check for a new file every second
    switch ( WaitForSingleObject( hTermEvt, 1000) )
    {
    case WAIT_OBJECT_0:
      // The thread was told to terminate
      XMLPlatformUtils::Terminate();
      return 0;
    default:
      // Check for check-in response files
      sprintf(szFilename, "c:\\%s\\*.xml", szBasePath);
      hFind = FindFirstFile(szFilename, &findFileData);
      bool fMore = true;
      while ( fMore && hFind!=INVALID_HANDLE_VALUE ) {
        sprintf( szFileURL, "file:///checkin/response/%s", 
                 findFileData.cFileName);
        // A file exists, attempt to parse it
        static const XMLCh gLS[] 
          = {chLatin_L,chLatin_S,chNull};

        DOMImplementation* impl 
          = DOMImplementationRegistry
            ::getDOMImplementation(gLS);
        DOMBuilder* parser = 
          ((DOMImplementationLS*)impl)->createDOMBuilder(
              DOMImplementationLS::MODE_SYNCHRONOUS, 0);
        try {
          DOMCountErrorHandler errorHandler;
          parser->setErrorHandler(&errorHandler);
          // Parse the XML file and traverse the DOM
          DOMDocument* doc = parser->parseURI(X(szFileURL));
          DOMNode* elem = (DOMNode*)doc->getDocumentElement();
          if ( elem ) {
            char szLastName[32];
            char szFirstName[32];
            char szStatus[32];
            GetNodeValue(elem, "Last", szLastName);
            GetNodeValue(elem, "First", szFirstName);
            GetNodeValue(elem, "Status", szStatus);
            char message[128];
            sprintf(message, "Payment for %s %s %s", szFirstName, 
               szLastName, szStatus );
            ::MessageBox( NULL, message, "Payment Status", MB_OK);
          }
        }
        catch(DOMException& de) {
          cout << "Exception parsing document: " << de.msg;
        }
        catch (...) { }
        delete parser;
        char szFileDel[128];
        sprintf(szFileDel, "c:\\%s\\%s", szBasePath, 
           findFileData.cFileName );
        DeleteFile( szFileDel );
        fMore = FindNextFile(hFind, &findFileData);
      }
      FindClose(hFind);
      break;
    }
  }
  XMLPlatformUtils::Terminate();
  return 0;
}