home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mmoshead.zip / samples / mci / mci.cc < prev    next >
Text File  |  1994-02-20  |  2KB  |  93 lines

  1. //////////////////////////////////////////
  2. // mci -- an interpreter for MCI scripts
  3. //
  4. // using emx 0.8h, mm4emx 1.0
  5. //
  6. //     based on a C program by
  7. //     John J. McDonough
  8. //
  9. // Marc E.E. van Woerkom, 2/94
  10. //
  11.  
  12.  
  13. #include <iostream.h>
  14. #include <fstream.h>
  15.  
  16. #include <os2.h>
  17.  
  18. #define  INCL_OS2MM
  19. #define  INCL_MCIOS2
  20. #include <os2me.h>
  21.  
  22.  
  23. //
  24. // this sample demonstrates the following MMPM/2 API's:
  25. //
  26. //     mciSendString()      send a MCI command string, receive an answer
  27. //     mciGetErrorString()  look up the error string for the error code
  28. //
  29.  
  30. int main(int argc, char* argv[])
  31. {
  32.     if ( argc != 2 ) {
  33.         cerr << "usage: mci <filename>\n";
  34.         return 1;
  35.     }
  36.  
  37.     ifstream infile(argv[1]);
  38.     if (!infile) {
  39.         cerr << "error: can't open input file " << argv[1] << '\n';
  40.         return 2;
  41.     }
  42.  
  43.     int line = 0;
  44.  
  45.     const bsize = 128;
  46.     char buff[bsize];
  47.  
  48.     while (!infile.eof()) {
  49.         char c = infile.peek();  // peek one char forward
  50.  
  51.         if (infile.good()) {
  52.  
  53.             infile.get(buff, bsize, '\n');
  54.  
  55.             cout.width(3);
  56.             cout << ++line << ": [" << buff << "]\n";
  57.  
  58.             if (c != '#') {
  59.  
  60.                 const rsize = 128;
  61.                 char rbuff[rsize];
  62.                 for (int i=0; i<rsize; i++) rbuff[i] = 0;
  63.  
  64.                 ULONG rc = mciSendString(buff,   // buffer with MCI string
  65.                                          rbuff,  // return buffer
  66.                                          rsize,  // rbuff size
  67.                                          0,      // no callback window handle
  68.                                          0);     // no user parameter
  69.  
  70.                 if (rc == MCIERR_SUCCESS) {
  71.                     if (rbuff[0])
  72.                         cout << "      -> " << rbuff << "\n\n";
  73.                 }
  74.                 else {
  75.                     ULONG rc2 = mciGetErrorString(rc,      // error code
  76.                                                   rbuff,   // return buffer
  77.                                                   rsize);  // rbuff size
  78.  
  79.                     if (rc2 == MCIERR_SUCCESS)
  80.                         cerr << "      -> MCI error: " << rbuff << "\n\n";
  81.                     else
  82.                         cerr << "      -> error #" << rc << " has occured!\n\n";
  83.                 }
  84.             }
  85.         }
  86.  
  87.         infile.get(c);  // eat the \r after the \n
  88.     }
  89.  
  90.     return 0;
  91. }
  92.  
  93.