home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / mm / mcispy / mcisubs.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  25KB  |  741 lines

  1. /*********************** START OF SPECIFICATIONS *******************************
  2. *
  3. * SOURCE FILE NAME: MCISUBS.C
  4. *
  5. * DESCRIPTION: MCISPY helper routines.
  6. *
  7. *              Copyright (c) IBM Corporation   1993
  8. *                        All Rights Reserved
  9. *
  10. *
  11. *********************** END OF SPECIFICATIONS ********************************/
  12. #define INCL_WIN                        /* OS/2 2.x Win include            */
  13. #define INCL_PM                         /* Presentation Manager include    */
  14. #define INCL_DOS                        /* OS/2 2.x DOS API include        */
  15. #include <os2.h>                        /* OS/2 2.x System include         */
  16. #include <stdio.h>                      /* C Standard funcs include        */
  17. #include <stdlib.h>                     /* C Standard library include      */
  18. #include <string.h>                     /* C String Functions include      */
  19. #include <stdarg.h>                     /* C Standard Arguments include    */
  20. #define INCL_OS2MM                      /* OS/2 2.X MM Include             */
  21. #include <os2me.h>                      /* Multimedia System include       */
  22. #include "mcispy.h"                     /* Component Private Definitions   */
  23. extern   MCISPY_BLOCK      SpyBlock;    /* MCISPY Application Data Block   */
  24. extern   MCIMessageTable   MCIMsgTbl[]; /* Global Table of MCI Messages    */
  25. LONG (* APIENTRY RegEntryProc) (HWND,ULONG);/* RegisterSpy() Func Pointer  */
  26.  
  27. /****************************START OF SPECIFICATIONS *************************
  28. *
  29. * FUNCTION:    GetSharedMemory
  30. *
  31. * DESCRIPTION: Obtain Shared Memory.
  32. *
  33. * OS/2 API's USED: DosGetSharedMem()
  34. *
  35. *****************************END OF SPECIFICATIONS ***************************/
  36. void GetSharedMemory(MCISPY_BLOCK *pSpyBlock)
  37. {
  38.   ULONG rc;
  39.  
  40.   rc = DosGetNamedSharedMem (&pSpyBlock->pvPacket,
  41.                             (PSZ) "\\SHAREMEM\\SPYPACK.DAT",
  42.                              PAG_READ |PAG_WRITE);
  43.  
  44.   if (rc)
  45.      mprintf ("Error Getting Shared Memory %d\n",rc);
  46.  
  47. }
  48.  
  49. /****************************START OF SPECIFICATIONS *************************
  50. *
  51. * FUNCTION:    OpenFileDlg
  52. *
  53. * DESCRIPTION: Open File Dialog.
  54. *
  55. * OS/2 API's USED: WinFileDlg().
  56. *
  57. *****************************END OF SPECIFICATIONS ***************************/
  58. RC OpenFileDlg (HWND hwndOwner,PSZ pszTitle,PSZ FileName, PSZ FullFile)
  59. {
  60.    FILEDLG  pfdFileDlg;                  /* File Dialog Structure */
  61.    HWND     hwndFileDlg;                 /* Handle to the above   */
  62.  
  63.    /* Initialize the structure to 0 */
  64.  
  65.    memset (&pfdFileDlg,0,sizeof(FILEDLG));
  66.  
  67.    pfdFileDlg.cbSize   = sizeof(FILEDLG);
  68.    pfdFileDlg.fl       = FDS_HELPBUTTON | FDS_CENTER | FDS_OPEN_DIALOG ;
  69.    pfdFileDlg.pszTitle = pszTitle;
  70.  
  71.    strcpy (pfdFileDlg.szFullFile,FullFile);
  72.  
  73.    hwndFileDlg = WinFileDlg (HWND_DESKTOP,hwndOwner,&pfdFileDlg);
  74.  
  75.    if (hwndFileDlg == NULLHANDLE)
  76.     {
  77.        mprintf ("File Dialog Creation Error\n");
  78.        return (TRUE);
  79.     }
  80.  
  81.    if (hwndFileDlg && (pfdFileDlg.lReturn == DID_OK))
  82.     {
  83.        strcpy (FileName,pfdFileDlg.szFullFile);
  84.        return (FALSE);
  85.     }
  86.  
  87.    if (hwndFileDlg && (pfdFileDlg.lReturn == DID_CANCEL))
  88.    {
  89.        return (TRUE);
  90.    }
  91.    return (FALSE);
  92. }
  93.  
  94. /****************************START OF SPECIFICATIONS *************************
  95. *
  96. * FUNCTION:    OpenFile
  97. *
  98. * DESCRIPTION: Open File.
  99. *
  100. * OS/2 API's USED: DosOpen.
  101. *
  102. *****************************END OF SPECIFICATIONS ***************************/
  103. APIRET OpenFile(PSZ szFileName,ULONG *pFileHandle)
  104. {
  105.    ULONG    ulAction;                 /* Action to be taken */
  106.    APIRET   RetCode;                  /* API return code    */
  107.    APIRET   rc;                       /* API return code    */
  108.    char     szHeader[256];            /* LogFile Header     */
  109.    HFILE    FileHandle;               /* Temp FileHandle    */
  110.    ULONG    ulBytesWritten;           /* Hedaer Bytes       */
  111.  
  112.    RetCode = DosOpen (szFileName, pFileHandle, &ulAction, 0,
  113.                       FILE_NORMAL,
  114.                       OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW,
  115.                       OPEN_FLAGS_WRITE_THROUGH | OPEN_FLAGS_NO_CACHE|
  116.                       OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYNONE|
  117.                       OPEN_ACCESS_READWRITE,
  118.                       0);
  119.  
  120.    if (!RetCode)
  121.     {
  122.  
  123.        FileHandle = *pFileHandle;
  124.        sprintf (szHeader,"%s\t\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n","Date","Time","PID","DeviceID",
  125.                "MCI Message", "Flags","UserParam","Data");
  126.        rc = DosWrite (FileHandle,szHeader,strlen(szHeader),&ulBytesWritten);
  127.  
  128.     }
  129.  
  130.    return (RetCode);
  131. }
  132.  
  133. /****************************START OF SPECIFICATIONS *************************
  134. *
  135. * FUNCTION:    Write2File
  136. *
  137. * ARGUMENTS:   HFILE FileHandle,   PSZ buffer
  138. *
  139. * RETURN:      RC
  140. *
  141. * DESCRIPTION: This function gets Date and Time and write it to the log file
  142. *
  143. * OS/2 API's USED: DosGetDateTime, DosWrite
  144. *
  145. * C FUNCTION CALLS: Sprintf
  146. *
  147. **************************************************************************/
  148. APIRET Write2File(HFILE FileHandle,PSZ buffer)
  149. {
  150.    ULONG    ulBytesWritten;            /* Bytes Written   */
  151.    APIRET   ReturnCode;                /* API return Code */
  152.    CHAR     chEOL[2] = "\r\n";         /* End of Line     */
  153.    CHAR     szTimeDate[32];            /* Time and Date   */
  154.    DATETIME dt;                        /* Date and Time   */
  155.    ULONG    rc;                        /* API Return      */
  156.  
  157.  
  158.    if (FileHandle == (HFILE)NULL)
  159.        return(1) ;
  160.  
  161.    if (buffer == (PSZ)NULL)
  162.        return(1) ;
  163.  
  164.    ReturnCode = DosGetDateTime(&dt);
  165.    if (ReturnCode)
  166.    {
  167.        strcpy (buffer, "DosGetDateTime failure:");
  168.        DosWrite (FileHandle,buffer, strlen(buffer),&ulBytesWritten);
  169.        return (ReturnCode);
  170.    }
  171.  
  172.    sprintf (szTimeDate,"%04d-%02d-%02d  %02d:%02d:%04d  ",
  173.             dt.year, dt.month,dt.day,dt.hours,dt.minutes,
  174.             dt.seconds );
  175.  
  176.  
  177.    ReturnCode = DosWrite (FileHandle,szTimeDate,
  178.                           strlen(szTimeDate),&ulBytesWritten);
  179.  
  180.    ReturnCode = DosWrite (FileHandle,buffer,
  181.                           strlen(buffer),&ulBytesWritten);
  182.  
  183.    ReturnCode = DosWrite (FileHandle, chEOL,
  184.                           strlen(chEOL),&ulBytesWritten);
  185.  
  186.    return (ReturnCode);
  187.  
  188. }
  189.  
  190. /****************************START OF SPECIFICATIONS *************************
  191. *
  192. * FUNCTION:    RegisterSpyWithMDM
  193. *
  194. *
  195. * DESCRIPTION: Register MCISPY with MDM
  196. *
  197. **************************************************************************/
  198. VOID  RegisterSpyWithMDM (MCISPY_BLOCK *pSpyBlock)
  199. {
  200.    APIRET                 rc ;              /* API Return Code    */
  201.    char                   LoadError[255];   /* Load Errors        */
  202.    HMODULE                ModuleHandle;     /* ModuleHandle       */
  203.  
  204.  
  205.    rc = DosLoadModule ((PSZ)LoadError, sizeof(LoadError),
  206.                        (PSZ)"MDM",
  207.                        &ModuleHandle);
  208.    if (rc)
  209.     {
  210.       mprintf ("Error Loading MDM.DLL %d\n",rc);
  211.       DosExit (0,0);
  212.     }
  213.  
  214.    rc = DosQueryProcAddr(ModuleHandle, 0L,
  215.                          (PSZ)"RegisterSpy", (PFN *)&RegEntryProc);
  216.  
  217.    if (rc)
  218.     {
  219.       mprintf ("Error Proc Address(RegisterSpy)  %d\n",rc);
  220.       DosExit (0,0);
  221.     }
  222.  
  223.    rc = DosQueryProcAddr(ModuleHandle, 0L,
  224.                          (PSZ)"QueryOpenInstance", (PFN *)&(pSpyBlock->QueryOpenInstance));
  225.  
  226.    if (rc)
  227.     {
  228.       mprintf ("Error Proc Address(QueryOpenInstance)  %d\n",rc);
  229.       DosExit (0,0);
  230.     }
  231.  
  232.    rc = DosQueryProcAddr(ModuleHandle, 0L,
  233.                          (PSZ)"SpySystemSounds", (PFN *)&(pSpyBlock->SystemSounds));
  234.  
  235.    if (rc)
  236.     {
  237.       mprintf ("Error Proc Address(SystemSounds)  %d\n",rc);
  238.       DosExit (0,0);
  239.     }
  240.  
  241.  
  242.    /* Register Spy with MDM */
  243.    rc = RegEntryProc ((HWND)pSpyBlock->hwnd1,TRUE);
  244.  
  245.  
  246.    if (rc)
  247.     {
  248.       mprintf ("Only One Instance Of MCISPY is allowed \n");
  249.       DosExit (0,0);
  250.     }
  251.  
  252.    /* Initially Disable Driver Notifications */
  253.    pSpyBlock->SystemSounds (FALSE);
  254.  
  255. }
  256.  
  257. /****************************START OF SPECIFICATIONS *************************
  258. *
  259. * FUNCTION:    DisplayMCIMsg
  260. *
  261. * ARGUMENTS:  Shared memory Data and Packet
  262. *
  263. * RETURN:
  264. *
  265. * DESCRIPTION: Display the message.
  266. *
  267. **************************************************************************/
  268. void  DisplayMCIMsg (MCISPY_BLOCK * pSpyBlock)
  269.  {
  270.    USHORT          i,j;                         /* Loop Indicies     */
  271.    char            szMsg[124];                  /* Message String    */
  272.    char            Mlebuffer[1024];             /* Mle Buffer        */
  273.    THREAD_BLOCK    *pNotPacket;                 /* Shared Mem Packet */
  274.    USHORT          usDeviceType;                /* Device Type       */
  275.    BOOL            fFoundMsg = FALSE;
  276.    char     szSpace[11]= "    ";
  277.    char     szSpace2[50]="                                            ";
  278.  
  279.  
  280.    /* Derefernce the Shared memory packet   */
  281.  
  282.    pNotPacket = (THREAD_BLOCK *)pSpyBlock->pvPacket;
  283.    memset (Mlebuffer,0,sizeof(Mlebuffer));
  284.  
  285.    switch (pNotPacket->wMsg)
  286.      {
  287.      case MM_MCIPOSITIONCHANGE:
  288.           if (MCIMsgTbl[58].fExclude)
  289.            {
  290.               return ;
  291.            }
  292.           sprintf (Mlebuffer,"%03d %s %02d %s %s  %d %s %04d \n",
  293.                    pNotPacket->ulPID,szSpace, pNotPacket->wDevID,szSpace,
  294.                    "  MM_MCIPOSITIONCHANGE     Media Position = ",
  295.                    pNotPacket->dwParam1,szSpace,  pNotPacket->wUserParm);
  296.           fFoundMsg = TRUE;
  297.       break;
  298.  
  299.       default:
  300.            if (pNotPacket->wMsg == MM_MCIPASSDEVICE)
  301.               return;
  302.           /* First obtain the device type of this device id */
  303.           if (pSpyBlock->fDevTypFil)
  304.            {
  305.               /* Update Open Instance Information */
  306.               pSpyBlock->QueryOpenInstance ((OPEN_LIST *)&pSpyBlock->OpenList,FALSE);
  307.  
  308.               for (j=0; j < pSpyBlock->OpenList.ulNumOpen; j++)
  309.                 {
  310.                    if (pSpyBlock->OpenList.ulOpenList[j].ulDevId == pNotPacket->wDevID)
  311.                     {
  312.                        usDeviceType =pSpyBlock->OpenList.ulOpenList[j].usDevTyp;
  313.                     } /* Current Device Id = OpenList Id */
  314.                 } /* Number of Open Instances */
  315.  
  316.               /* Check if device type for this device type is on.
  317.               ** If it is then we return without displaying this message.
  318.               */
  319.               for (i=0; i <MAXDEVICES; i++)
  320.                 {
  321.                   if (pSpyBlock->ulDevTypFil[i] == usDeviceType)
  322.                    {
  323.                       return;
  324.                    } /* device type match */
  325.                 } /* max Devices */
  326.            } /* Device Type Filter is on */
  327.  
  328.           /* Check if Global MCI message filter for this message is on.
  329.           ** If it is then we return without displaying this message.
  330.           */
  331.           for (i=0; i <MAX_MCI_MSGS; i++ )
  332.             {
  333.               if (MCIMsgTbl[i].usMsg == pNotPacket->wMsg)
  334.                {
  335.                   /* Global Message Filter is Active for this message */
  336.  
  337.                   if (MCIMsgTbl[i].fExclude)
  338.                    {
  339.                      return;
  340.                    }
  341.  
  342.                   strcpy (szMsg,MCIMsgTbl[i].szMessage);
  343.                   strncat (szMsg,szSpace2,27-strlen(szMsg));
  344.                   fFoundMsg = TRUE;
  345.                   break;
  346.                }/* Found the Message */
  347.             } /* Max MCI Msgs loop */
  348.             if (pSpyBlock->fDevIdFil)
  349.              {
  350.                 /* Update Open Instance Information */
  351.                 pSpyBlock->QueryOpenInstance ((OPEN_LIST *)&pSpyBlock->OpenList,FALSE);
  352.                 for (j=0; j < pSpyBlock->OpenList.ulNumOpen; j++)
  353.                   {
  354.                      if (pSpyBlock->OpenList.ulOpenList[j].ulDevId == pNotPacket->wDevID)
  355.                       {
  356.                         if (pSpyBlock->OpenList.ulOpenList[j].fExclude)
  357.                          {
  358.                            return;
  359.                          }/* Exclude is true */
  360.                       } /* Current Device Id = OpenList Id */
  361.                   } /* Number of Open Instances */
  362.              } /* Device Id Filter in use */
  363.  
  364.           if (pNotPacket->wDevID  == 65535)
  365.                pNotPacket->wDevID = 0;
  366.           if (fFoundMsg)
  367.            {
  368.              sprintf (Mlebuffer,"%03d %s %02d  %s  %s  0x%05X %s  %04d %s 0x%05X \n",
  369.                       pNotPacket->ulPID, szSpace,pNotPacket->wDevID,szSpace,
  370.                       szMsg, pNotPacket->dwParam1,szSpace,
  371.                       pNotPacket->wUserParm,szSpace,pNotPacket->dwParam2);
  372.  
  373.            }
  374.       break;
  375.  
  376.      }/* Switch */
  377.    if (fFoundMsg)
  378.     {
  379.        WinSendMsg (pSpyBlock->hwndMLE,MLM_SETSEL,MPFROMLONG(pSpyBlock->ipt),
  380.                    MPFROMLONG(pSpyBlock->ipt));
  381.  
  382.        WinSendMsg (pSpyBlock->hwndMLE,MLM_INSERT,MPFROMLONG(Mlebuffer),
  383.                    (MPARAM)0);
  384.  
  385.        pSpyBlock->ipt= (IPT)WinSendMsg (pSpyBlock->hwndMLE,MLM_QUERYSEL,MPFROMSHORT(MLFQS_CURSORSEL),
  386.                                         0L);
  387.  
  388.        if (pSpyBlock->fNoLog)
  389.            Write2File (pSpyBlock->hfileLog,Mlebuffer);
  390.  
  391.     }/* Found Msg */
  392.  }
  393.  
  394. /****************************START OF SPECIFICATIONS *************************
  395. *
  396. * FUNCTION:    mprintf
  397. *
  398. * ARGUMENTS:   Error Message String.
  399. *
  400. * RETURN:      None.
  401. *
  402. * DESCRIPTION: Write to Log File for command logging.
  403. *
  404. * OS/2 API's USED:   WinAlarm()
  405. *                    WinMessageBox().
  406. *
  407. * C FUNCTION CALLS:  malloc()
  408. *                     va_start();
  409. *
  410. *
  411. * INTERNAL FUNCTION REFERENCES: None.
  412. *
  413. *****************************END OF SPECIFICATIONS ***************************/
  414.  
  415. LONG mprintf(PSZ format, ...)
  416. {
  417.    va_list pArg;
  418.    SZ     buffer[513];
  419.    LONG    lCount;
  420.  
  421.    WinAlarm( HWND_DESKTOP, WA_ERROR );
  422.  
  423.  
  424.    va_start(pArg, format);
  425.  
  426.    lCount = vsprintf(buffer, format, pArg);
  427.  
  428.    WinMessageBox( HWND_DESKTOP,       /* parent window handle    */
  429.                   HWND_DESKTOP,       /* owner window handle     */
  430.                   buffer,             /* pointer to message text */
  431.                   "MCISPY",            /* pointer to title text   */
  432.                   MSG_BOX_ID,         /* message box identifier  */
  433.                   MB_OK | MB_ERROR ); /* message box style       */
  434.  
  435.    return lCount;
  436. }   /*  end of mprintf()  */
  437.  
  438. /****************************START OF SPECIFICATIONS *************************
  439. *
  440. * FUNCTION     LongToString
  441. *
  442. * C FUNCTION CALLS:     _ltoa()
  443. *                       malloc()
  444. *
  445. * GLOBAL VARIABLES MODIFIED:
  446. *
  447. *****************************END OF SPECIFICATIONS ***************************/
  448. PSZ LongToString(LONG l)
  449. {
  450.     PSZ   pszReturn;     /* Temporary Storage */
  451.     CHAR  cString[34];   /* Buffer            */
  452.  
  453.     pszReturn = _ltoa(l, cString, 10);
  454.     return ((PSZ)cString);
  455.  
  456. }  /* LongToString */
  457.  
  458. /****************************START OF SPECIFICATIONS *************************
  459. *
  460. * FUNCTION: Initialize()
  461. *
  462. * ARGUMENTS:    None.
  463. *
  464. * RETURN:       None.
  465. *
  466. * DESCRIPTION:
  467. *
  468. * OS/2 API's USED: WinCreateHelpInstance()
  469. *                  WinDestroyHelpInstance()
  470. *
  471. * C FUNCTION CALLS:
  472. *
  473. * INTERNAL FUNCTION REFERENCES: None.
  474. *
  475. * GLOBAL VARIABLES REFERENCED: helpinit data structure.
  476. *                              hwndHelpInstance.
  477. *
  478. * GLOBAL VARIABLES MODIFIED: helpinit data structure.
  479. *                            hwndHelpInstance.
  480. *
  481. *****************************END OF SPECIFICATIONS ***************************/
  482. VOID Initialize(MCISPY_BLOCK * pSpyBlock)
  483. {
  484.     int        i;          /* Loop Index  */
  485.     APIRET     rc;         /* Return Code */
  486.     HELPINIT   helpinit;   /* Help Init   */
  487.  
  488.     /* Initialize our default log and script file names */
  489.  
  490.     strcpy (pSpyBlock->szLogFile,"MCISPY.LOG");
  491.     OpenFile (pSpyBlock->szLogFile,&pSpyBlock->hfileLog);
  492.  
  493.  
  494.     /* Initilaize the Help Manager structures */
  495.  
  496.     pSpyBlock->fNoCmd = pSpyBlock->fNoStr = pSpyBlock->fNoDrv = FALSE;
  497.     pSpyBlock->fNoLog = FALSE;
  498.     memset (&helpinit,0,sizeof(HELPINIT));
  499.  
  500.     helpinit.cb                       = sizeof(HELPINIT);
  501.     helpinit.ulReturnCode             = 0LU;
  502.     helpinit.pszTutorialName          = (PSZ)NULL;
  503.     helpinit.phtHelpTable      = (PHELPTABLE)MAKELONG(MAINHELPTABLE, 0xFFFF);
  504.     helpinit.hmodAccelActionBarModule = NULLHANDLE;
  505.     helpinit.idAccelTable             = 0;
  506.     helpinit.idActionBar              = 0;
  507.     helpinit.pszHelpWindowTitle       = "MultiMedia MCI Spy Program V1.0";
  508.     helpinit.hmodHelpTableModule      = NULLHANDLE;
  509.     helpinit.fShowPanelId             = CMIC_HIDE_PANEL_ID;
  510.     helpinit.pszHelpLibraryName       = "MCISPY.HLP";
  511.  
  512.    // if((pSpyBlock->hwndHelpInstance = WinCreateHelpInstance(pSpyBlock->hab, &pSpyBlock->helpinit))==NULLHANDLE)
  513.     if((pSpyBlock->hwndHelpInstance = WinCreateHelpInstance(WinQueryAnchorBlock(HWND_DESKTOP),  &helpinit))==NULLHANDLE)
  514.      {
  515.        mprintf ("Help Creation Error\n");
  516.      }
  517.     else
  518.      if (helpinit.ulReturnCode)
  519.       {
  520.         mprintf ("Help Creation Error\n");
  521.         WinDestroyHelpInstance(pSpyBlock->hwndHelpInstance);
  522.         pSpyBlock->hwndHelpInstance = 0;
  523.       }
  524.  
  525.      /* Associate Help */
  526.      if (pSpyBlock->hwndHelpInstance )
  527.         WinAssociateHelpInstance( pSpyBlock->hwndHelpInstance, pSpyBlock->hwnd1 );
  528.  
  529.      DosRequestMutexSem (pSpyBlock->hmtxPrntSem, SEM_INDEFINITE_WAIT);
  530.     /* Register Our App with MDM for Spying MCI Messages */
  531.     RegisterSpyWithMDM(pSpyBlock);
  532.  
  533.     /* Query Open Instance information */
  534.  
  535.     pSpyBlock->QueryOpenInstance ((OPEN_LIST *)&pSpyBlock->OpenList,TRUE);
  536.     pSpyBlock->QueryOpenInstance ((OPEN_LIST *)&pSpyBlock->OpenList,FALSE);
  537.     /*
  538.     ** Give up the Print Semaphore
  539.     */
  540.     DosReleaseMutexSem (pSpyBlock->hmtxPrntSem);
  541.  
  542. }
  543.  
  544. /****************************START OF SPECIFICATIONS *************************
  545. *
  546. * FUNCTION:    QueryInstalledDevices
  547. *
  548. * ARGUMENTS:
  549. *
  550. * RETURN:
  551. *
  552. * DESCRIPTION: To Query MMPM/2 and obtain list of all installed
  553. *              audio devices and to initialize device specific info.
  554. *
  555. * OS/2 API's USED:  mciSendCommand() MMPM/2 Command Interface API
  556. *
  557. *
  558. * C FUNCTION CALLS: memset()  malloc()
  559. *                   strxxx()  free ()
  560. *
  561. **************************************************************************/
  562. VOID QueryInstalledDevices (MCISPY_BLOCK * pSpyBlock)
  563. {
  564.     SZ                     pszAllDevNames[1024]; /* All MMPM/2 Device Names */
  565.     SZ                     retbuffer[MAX_SYSINFO_RETURN];/* Return buffer      */
  566.     CHAR                   tokensep[] = " ";     /* Token Seperators        */
  567.     PCHAR                  pchWord;              /* Word pointer            */
  568.     PSZ                    pszTemp ;             /* Temporary Storage       */
  569.     USHORT                 i,j = 0;              /* Loop Indicies           */
  570.     APIRET                 ReturnCode ;          /* API Return Code         */
  571.     MCI_SYSINFO_PARMS      SysInfo ;             /* Generic Sys Info Struct */
  572.     MCI_SYSINFO_QUERY_NAME SysInfoQName ;        /* Sys Info Qry Name Str   */
  573.     MCI_SYSINFO_LOGDEVICE  SysInfoLogDev;        /* Sys Info Log Dev  Str   */
  574.  
  575.     /* Obtain The Serialization Semaphore */
  576.  
  577.     DosRequestMutexSem (pSpyBlock->hmtxPrntSem, SEM_INDEFINITE_WAIT);
  578.  
  579.     /* Initialize the SysInfo structures */
  580.     memset (retbuffer,0,sizeof(retbuffer));
  581.     memset (pszAllDevNames,0,sizeof(pszAllDevNames));
  582.     memset ((PCH)&SysInfo,0,sizeof(MCI_SYSINFO_PARMS));
  583.     memset ((PCH)&SysInfoQName,0,sizeof(MCI_SYSINFO_QUERY_NAME));
  584.     memset ((PCH)&SysInfoLogDev,0,sizeof(MCI_SYSINFO_LOGDEVICE));
  585.  
  586.     SysInfo.pszReturn = (PSZ)retbuffer;
  587.     SysInfo.ulRetSize = MAX_SYSINFO_RETURN;
  588.  
  589.     /* First obtain the number of devices installed */
  590.  
  591.     ReturnCode = mciSendCommand ((USHORT) MCI_ALL_DEVICE_ID,
  592.                                  (USHORT) MCI_SYSINFO,
  593.                                  (ULONG)  MCI_SYSINFO_QUANTITY | MCI_WAIT,
  594.                                  (PVOID)  &SysInfo,
  595.                                  (USHORT) NULL );
  596.  
  597.     /* Allocate memory for return information */
  598.  
  599.     if (!ReturnCode)
  600.      {
  601.         pSpyBlock->usNumDevices = (USHORT) atoi (retbuffer);
  602.      }
  603.     /* Obtain the names of devices installed */
  604.  
  605.     memset (&SysInfo,0,sizeof(MCI_SYSINFO_PARMS));
  606.     SysInfo.pszReturn = (PSZ)pszAllDevNames;
  607.     SysInfo.ulRetSize = 1024 ;
  608.  
  609.     ReturnCode = mciSendCommand ((USHORT) MCI_ALL_DEVICE_ID,
  610.                                  (USHORT) MCI_SYSINFO,
  611.                                  (ULONG)  MCI_SYSINFO_NAME | MCI_WAIT,
  612.                                  (PVOID)  &SysInfo,
  613.                                  (USHORT) NULL );
  614.  
  615.     if (!LOUSHORT(ReturnCode))
  616.      {
  617.        pchWord = strtok (pszAllDevNames,tokensep);
  618.  
  619.        for (i = 0; i < pSpyBlock->usNumDevices ; i++)
  620.          {
  621.           if (pchWord == NULL)
  622.               break;
  623.  
  624.           memset ((PCH)&SysInfo,0,sizeof(MCI_SYSINFO_PARMS));
  625.           memset ((PCH)&SysInfoQName,0,sizeof(MCI_SYSINFO_QUERY_NAME));
  626.  
  627.           strcpy (SysInfoQName.szLogicalName,pchWord);
  628.  
  629.           /* Get the logical name */
  630.  
  631.           SysInfo.ulItem = MCI_SYSINFO_QUERY_NAMES ;
  632.           SysInfo.pSysInfoParm = &SysInfoQName ;
  633.           ReturnCode = mciSendCommand ((USHORT) NULL,
  634.                                        (USHORT) MCI_SYSINFO,
  635.                                        (ULONG)  MCI_SYSINFO_ITEM | MCI_WAIT,
  636.                                        (PVOID)  &SysInfo,
  637.                                        (USHORT) NULL );
  638.  
  639.           if (LOUSHORT(ReturnCode))
  640.             break;
  641.  
  642.           strcpy(pSpyBlock->PhysicalDevData[j].szLogDevName,
  643.                  SysInfoQName.szLogicalName);
  644.  
  645.  
  646.           /*
  647.           ** Now Set Up Product Information and PDD Names
  648.           ** of associated devices.
  649.           */
  650.  
  651.            memset (&SysInfoLogDev,0,sizeof(MCI_SYSINFO_LOGDEVICE));
  652.            SysInfo.ulItem = MCI_SYSINFO_QUERY_DRIVER ;
  653.            SysInfo.pSysInfoParm = &SysInfoLogDev ;
  654.  
  655.            strcpy (SysInfoLogDev.szInstallName,
  656.                    SysInfoQName.szInstallName);
  657.  
  658.            ReturnCode = mciSendCommand((USHORT) NULL,
  659.                                        (USHORT) MCI_SYSINFO,
  660.                                        (ULONG)  MCI_SYSINFO_ITEM | MCI_WAIT,
  661.                                        (PVOID)  &SysInfo,
  662.                                        (USHORT) NULL );
  663.  
  664.  
  665.           if (LOUSHORT(ReturnCode))
  666.             break;
  667.  
  668.            if (SysInfoLogDev.szPDDName !="")
  669.                strcpy(pSpyBlock->PhysicalDevData[j].szPhysicalDevName,
  670.                       SysInfoLogDev.szPDDName);
  671.  
  672.            if (SysInfoLogDev.szProductInfo !="")
  673.                strcpy(pSpyBlock->PhysicalDevData[j].szProductInfo,
  674.                   SysInfoLogDev.szProductInfo);
  675.  
  676.           j++;
  677.  
  678.          pchWord = strtok (NULL,tokensep); /* Get the Next Token */
  679.          } /* For Loop */
  680.      } /* No Return Code */
  681.  
  682.      /*
  683.      ** Give up the Print Semaphore
  684.      */
  685.      DosReleaseMutexSem (pSpyBlock->hmtxPrntSem);
  686. }
  687.  
  688. /****************************START OF SPECIFICATIONS *************************
  689. *
  690. * FUNCTION      Terminate
  691. *
  692. * ARGUMENTS:    None.
  693. *
  694. * RETURN:       None.
  695. *
  696. * DESCRIPTION: Terminate the application and release resourves.
  697. *
  698. * OS/2 API's USED: WinDestroyWindow()
  699. *                  WinDestroyHelpInstance()
  700. *                  WinDestroyMsgQueue()
  701. *                  WinTerminate()
  702. *
  703. * C FUNCTION CALLS:
  704. *
  705. * INTERNAL FUNCTION REFERENCES: None.
  706. *
  707. * GLOBAL VARIABLES REFERENCED: hab,hwnd1,hmq,
  708. *                              hwndHelpInstance.
  709. *
  710. * GLOBAL VARIABLES MODIFIED: hab,hwnd1,hmq,
  711. *                            hwndHelpInstance.
  712. *
  713. *****************************END OF SPECIFICATIONS ***************************/
  714. VOID Terminate (HMQ hmq)
  715. {
  716.   int i;
  717.  
  718.   /* DeRegister Spy with MDM */
  719.   RegEntryProc ((HWND)SpyBlock.hwnd1,FALSE);
  720.  
  721.   /* Close the current Log File */
  722.   DosClose (SpyBlock.hfileLog);
  723.  
  724.   /* Destroy the window */
  725.   WinDestroyWindow(SpyBlock.hwnd1);
  726.  
  727.   /* Destroy the Help instance */
  728.   if (SpyBlock.hwndHelpInstance)
  729.       WinDestroyHelpInstance (SpyBlock.hwndHelpInstance);
  730.  
  731.  
  732.   /* Destroy the message queue */
  733.   WinDestroyMsgQueue(SpyBlock.hmq );
  734.  
  735.   /* Terminate and release resources */
  736.   WinTerminate( SpyBlock.hab );
  737.  
  738. }
  739.  
  740.  
  741.