home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pencod.zip / MMSRV.C < prev    next >
Text File  |  1993-11-02  |  31KB  |  595 lines

  1. /******************************************************************************
  2. *                                                                             *
  3. *   Name:  MMSRV.C                                                            *
  4. *                                                                             *
  5. *   Copyright : COPYRIGHT IBM CORPORATION, 1993                               *
  6. *               LICENSED MATERIAL - PROGRAM PROPERTY OF IBM                   *
  7. *                                                                             *
  8. *   Description: Multi media handling routines.                               *
  9. *                                                                             *
  10. *   Hardware Requirement: Audio I/O Device.                                   *
  11. *                                                                             *
  12. *   Software Requirement: IBM OS/2 V2.1, Pen for OS/2 V 1.0 and MMPM/2 V1.1   *
  13. *                                                                             *
  14. *   Subroutine Names and their function:                                      *
  15. *                                                                             *
  16. *      mmsrvSetVolume : Set volume of speaker phone                           *
  17. *                                                                             *
  18. *      mmsrvAcquire : Acquire device before play and recording                *
  19. *                                                                             *
  20. *      mmsrvRelease : Release device after recording and playing is done      *
  21. *                                                                             *
  22. *      mmsrvStop : Stop device when STOP button is clicked when recording     *
  23. *                  and playing is done.                                       *
  24. *                                                                             *
  25. *      mmsrvClose : Close the device at end                                   *
  26. *                                                                             *
  27. *      mmsrvOpen : Open device at the beginning                               *
  28. *                                                                             *
  29. *      mmsrvPlay : Play device with recorded data (voice)                     *
  30. *                                                                             *
  31. *      mmsrvRecord : Record voice.                                            *
  32. *                    The MM_MCIPOSITIONCHANGE message is sent for every one   *
  33. *                    tenth second from the multi media to the Audio dialog    *
  34. *                    window while recording and playing.                      *
  35. *                                                                             *
  36. *  DISCLAIMER OF WARRANTIES.  The following [enclosed] code is                *
  37. *      sample code created by IBM Corporation. This sample code is not        *
  38. *      part of any standard or IBM product and is provided to you solely      *
  39. *      for  the purpose of assisting you in the development of your           *
  40. *      applications.  The code is provided "AS IS", without                   *
  41. *      warranty of any kind.  IBM shall not be liable for any damages         *
  42. *      arising out of your use of the sample code, even if they have been     *
  43. *      advised of the possibility of such damages.                            *
  44. *                                                                             *
  45. ******************************************************************************/
  46.  
  47. #define  INCL_DOS
  48. #define  INCL_WIN
  49. #define  INCL_GPI
  50. #define  INCL_PM
  51. #define  INCL_DOSFILEMGR
  52.  
  53. #include <os2.h>
  54. //#include <stdlib.h>
  55. //#include <stdio.h>
  56.  
  57. #define  INCL_MMIO
  58. #define  INCL_OS2MM
  59. #include <os2me.h>
  60. #include "mmsrv.h"
  61.  
  62. /*****************************************************************************
  63. *                                                                            *
  64. *   Subroutine Name : ShowError                                              *
  65. *                                                                            *
  66. *   Function: Give the error message with return code in a message box.      *
  67. *                                                                            *
  68. *   Parameters:                                                              *
  69. *                 PSZ   err:  error message string, INPUT                    *
  70. *                 ULONG errid: error code,          INPUT                    *
  71. *                                                                            *
  72. *****************************************************************************/
  73. VOID ShowError(PSZ  err, ULONG errid)
  74. {
  75.   char terr[100];
  76.  
  77.    sprintf(terr, "%s %d", err, errid);
  78.    WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, terr, "Attention", 0, MB_OK);
  79. }
  80.  
  81. /*****************************************************************************
  82. *                                                                            *
  83. *   Subroutine Name : mmsrvSetVolume                                         *
  84. *                                                                            *
  85. *   Function: Set volume level when user adjust the volume level in          *
  86. *             volume scroll bar.                                             *
  87. *                                                                            *
  88. *   Parameters:                                                              *
  89. *                USHORT usVolume: volume level, INPUT                        *
  90. *                                                                            *
  91. *   MMPM/2 API: mciSendCommand                                               *
  92. *                                                                            *
  93. *   MMPM/s Message handled: MCI_SET                                          *
  94. *                                                                            *
  95. *****************************************************************************/
  96. LONG APIENTRY mmsrvSetVolume( USHORT usVolume)
  97. {
  98.    ULONG                ulReturn = 0;  /* error value for mci returns   */
  99.    MCI_WAVE_SET_PARMS   mspSet;        /* set values for volume, etc.   */
  100.  
  101.    usLevel = usVolume;
  102.    if (usWaveId != 0)
  103.    {
  104.       /*******************************************************************
  105.       *  To set the volume,  first, the MCI_SET_PARMS structure must be  *
  106.       *  filled with the necessary values.  Then an MCI_SET command      *
  107.       *  should be issued to the device to perform the volume change.    *
  108.       *******************************************************************/
  109.       memset(&mspSet, 0, sizeof(mspSet));
  110.       mspSet.hwndCallback = (HWND) NULL;
  111.       mspSet.ulAudio    = MCI_SET_AUDIO_ALL;    /* set all channels     */
  112.       mspSet.ulLevel    = (ULONG) usVolume;     /* volume level desired */
  113.       ulReturn = mciSendCommand((USHORT) usWaveId,
  114.                                 MCI_SET,
  115.                                 MCI_WAIT | MCI_SET_AUDIO | MCI_SET_VOLUME,
  116.                                 (PVOID) &mspSet,
  117.                                 0);
  118.       if (ulReturn)
  119.          ShowError( "error while setting up the volume", ulReturn);
  120.    }
  121.    return ulReturn;
  122. }
  123.  
  124. /*****************************************************************************
  125. *                                                                            *
  126. *   Subroutine Name : mmsrvAcquire                                           *
  127. *                                                                            *
  128. *   Function: Acquire device before play and record.                         *
  129. *                                                                            *
  130. *   Parameters:  None.                                                       *
  131. *                                                                            *
  132. *   MMPM/2 API: mciSendCommand                                               *
  133. *                                                                            *
  134. *   MMPM/s Message handled: MCI_ACQUIREDEVICE                                *
  135. *                                                                            *
  136. *****************************************************************************/
  137. LONG APIENTRY mmsrvAcquire(VOID)
  138. {
  139.    MCI_GENERIC_PARMS mciGenericParms;
  140.    ULONG ulReturn;
  141.  
  142.    memset(&mciGenericParms, 0, sizeof(mciGenericParms));
  143.    if (ulReturn = mciSendCommand((USHORT) usWaveId,
  144.                                  MCI_ACQUIREDEVICE,
  145.                                  MCI_WAIT | MCI_EXCLUSIVE_INSTANCE,
  146.                                  (PVOID) &mciGenericParms,
  147.                                  0L))
  148.    {
  149.       ShowError("error during acquiredevice ", ulReturn);
  150.    }
  151.    return(ulReturn);
  152. }
  153.  
  154. /*****************************************************************************
  155. *                                                                            *
  156. *   Subroutine Name : mmsrvRelease                                           *
  157. *                                                                            *
  158. *   Function: Release device after play or record is done.                   *
  159. *                                                                            *
  160. *   Parameters:  None.                                                       *
  161. *                                                                            *
  162. *   MMPM/2 API: mciSendCommand                                               *
  163. *                                                                            *
  164. *   MMPM/s Message handled: MCI_RELEASEDEVICE                                *
  165. *                                                                            *
  166. *****************************************************************************/
  167. LONG APIENTRY mmsrvRelease(VOID)
  168. {
  169.    MCI_GENERIC_PARMS mciGenericParms;
  170.    ULONG             ulReturn;
  171.  
  172.    memset(&mciGenericParms, 0, sizeof(mciGenericParms));
  173.    if (ulReturn = mciSendCommand((USHORT) usWaveId,
  174.                                  MCI_RELEASEDEVICE,
  175.                                  MCI_WAIT,
  176.                                  (PVOID) &mciGenericParms,
  177.                                  0))
  178.    {
  179.       ShowError( "error occured in releasing the device ", ulReturn);
  180.    }
  181.    return(ulReturn);
  182. }
  183.  
  184. /*****************************************************************************
  185. *                                                                            *
  186. *   Subroutine Name : mmsrvStop                                              *
  187. *                                                                            *
  188. *   Function: Stop device  when the STOP button is clicked while recording   *
  189. *             or playing.                                                    *
  190. *                                                                            *
  191. *   Parameters:  None.                                                       *
  192. *                                                                            *
  193. *   MMPM/2 API: mciSendCommand                                               *
  194. *                                                                            *
  195. *   MMPM/s Message handled: MCI_STOP                                         *
  196. *                                                                            *
  197. *****************************************************************************/
  198. LONG APIENTRY mmsrvStop(VOID)
  199. {
  200.    ULONG             ulReturn = 0;
  201.    MCI_GENERIC_PARMS mciGenericParms;
  202.  
  203.    memset(&mciGenericParms, 0, sizeof(mciGenericParms));
  204.    if (ulReturn = mciSendCommand((USHORT) usWaveId,
  205.                                  MCI_STOP,
  206.                                  MCI_WAIT,
  207.                                  (PVOID) &mciGenericParms,
  208.                                  0))
  209.    {
  210.       ShowError( "error occured in stopping the device ", ulReturn);
  211.    }
  212.    return(ulReturn);
  213. }
  214.  
  215. /*****************************************************************************
  216. *                                                                            *
  217. *   Subroutine Name : mmsrvClose                                             *
  218. *                                                                            *
  219. *   Function: Close device when the Audio dialog window is closed.           *
  220. *                                                                            *
  221. *   Parameters:  None.                                                       *
  222. *                                                                            *
  223. *   MMPM/2 API: mciSendCommand                                               *
  224. *                                                                            *
  225. *   MMPM/s Message handled: MCI_CLOSE                                        *
  226. *                                                                            *
  227. *****************************************************************************/
  228. LONG APIENTRY mmsrvClose(VOID)
  229. {
  230.    ULONG             ulReturn = 0;
  231.    MCI_GENERIC_PARMS mciGenericParms;
  232.  
  233.    memset(&mciGenericParms, 0, sizeof(mciGenericParms));
  234.    if(ulReturn = mciSendCommand((USHORT) usWaveId,
  235.                                 MCI_CLOSE,
  236.                                 MCI_WAIT,
  237.                                 (PVOID) &mciGenericParms,
  238.                                 0))
  239.    {
  240.       ShowError("error in closing the device ", ulReturn);
  241.    }
  242.    usWaveId = 0;
  243.    usAmpId = 0;
  244.    return (ulReturn);
  245. }
  246.  
  247. /*****************************************************************************
  248. *                                                                            *
  249. *   Subroutine Name : mmsrvOpen                                              *
  250. *                                                                            *
  251. *   Function: Open  device at the beginnning for setup.                      *
  252. *                                                                            *
  253. *   Parameters :  HWND hwnd of audio dialog window, INPUT                    *
  254. *                                                                            *
  255. *   MMPM/2 API: mciSendCommand                                               *
  256. *                                                                            *
  257. *   MMPM/s Message handled: MCI_OPEN, MCI_SYSINFO, MCI_CLOSE, MCI_SET        *
  258. *                           MCI_SET_POSITION_ADVICE, MCI_CONNECTOR,          *
  259. *                           MCI_SET_CONNECTION                               *
  260. *                                                                            *
  261. *   Pseudo Code:  Give defaule system info.                                  *
  262. *                 Setup parameters for device ordinal number.                *
  263. *                 Specify device type.                                       *
  264. *                 Setup parameters for audio data file.                      *
  265. *                 Setup time format in milisecond.                           *
  266. *                 Setup input source.                                        *
  267. *                 Set the input level.                                       *
  268. *****************************************************************************/
  269. LONG APIENTRY mmsrvOpen(HWND hwnd)
  270. {
  271.   MCI_OPEN_PARMS       lpWaveOpen;        // Used for MCI_OPEN messages
  272.   MCI_CONNECTOR_PARMS  mciConnectorParms; /* for MCI_CONNECTOR               */
  273.   MCI_WAVE_SET_PARMS   mciWaveSetParms;   /* for MCI_SET, waveform devices   */
  274.   MCI_GENERIC_PARMS    mciGenericParms;   /* for MCI_ACQUIRE                 */
  275.   MCI_AMP_SET_PARMS    mciAmpSetParms;    /* for MCI_SET, amp/mix devices    */
  276.   MCI_CONNECTION_PARMS mciConnectionParms;/* for MCI_CONNECTION              */
  277.   MCI_SET_PARMS        mciSetParms;
  278.   MCI_POSITION_PARMS   mciSetPosParms;   /* to get periodic messages to show time */
  279.   ULONG                     ulReturn;
  280.  
  281.   MCI_SYSINFO_PARMS         mciSysinfoParms;
  282.   MCI_SYSINFO_DEFAULTDEVICE mciSysinfoDefaultdevice;
  283.   MCI_SYSINFO_QUERY_NAME    mciSysinfoQueryName;
  284.   ULONG                     ulError;
  285.   USHORT                    usDeviceTypeOpened; /* for device type opened    */
  286.  
  287.    memset( &mciSysinfoParms, 0, sizeof( mciSysinfoParms ) );
  288.    memset( &mciSysinfoDefaultdevice, 0, sizeof(mciSysinfoDefaultdevice));
  289.  
  290.    /**************************************************************************
  291.    *  Set up parameters to query the default device for                      *
  292.    *  MCI_DEVTYPE_WAVEFORM_AUDIO device type. If no explicit default exists, *
  293.    *  then the first device of the indicated type is implicitely the default.*
  294.    *                                                                         *
  295.    *  First, initialize MCI_SYSINFO_PARMS and MCI_SYSINFO_DEFAULTDEVICE      *
  296.    *  structures with the pertinent information then issue MCI_SYSINFO       *
  297.    *  command via mciSendCommand. The pSysInfoParm field points to the       *
  298.    *  MCI_SYSINFO_DEFAULTDEVICE structure. The default device name will be   *
  299.    *  returned in the szInstallName field.                                   *
  300.    **************************************************************************/
  301.    mciSysinfoParms.ulItem  = MCI_SYSINFO_QUERY_DEFAULT;
  302.    mciSysinfoParms.pSysInfoParm  = &mciSysinfoDefaultdevice;
  303.    mciSysinfoDefaultdevice.usDeviceType  = MCI_DEVTYPE_WAVEFORM_AUDIO;
  304.  
  305.    ulError = mciSendCommand( (USHORT) 0,
  306.                              MCI_SYSINFO,
  307.                              MCI_WAIT | MCI_SYSINFO_ITEM,
  308.                              (PVOID) &mciSysinfoParms,
  309.                              0);
  310.  
  311.    if (ulError == 0L)
  312.    {
  313.       memset( &mciSysinfoParms , 0, sizeof(MCI_SYSINFO_PARMS));
  314.       memset( &mciSysinfoQueryName , 0, sizeof(MCI_SYSINFO_QUERY_NAME));
  315.  
  316.       /************************************************************************
  317.       * Set up parameters to query the device ordinal value. This message     *
  318.       * query the given device name which is in the szInstallName field of the*
  319.       * MCI_SYSINFO_DEFAULTDEVICE structure and returns the ordinal value of  *
  320.       * the first device of that type. The pSysInfoParm field points to the   *
  321.       * MCI_SYSINFO_QUERY_NAME structure which has the default device name.   *
  322.       ************************************************************************/
  323.       mciSysinfoParms.ulItem  = MCI_SYSINFO_QUERY_NAMES;
  324.       mciSysinfoParms.pSysInfoParm  = &mciSysinfoQueryName;
  325.       memmove( &mciSysinfoQueryName.szInstallName,
  326.                &mciSysinfoDefaultdevice.szInstallName,
  327.                sizeof(mciSysinfoQueryName.szInstallName ) );
  328.  
  329.       ulError = mciSendCommand( (USHORT) 0,
  330.                                 MCI_SYSINFO,
  331.                                 MCI_WAIT | MCI_SYSINFO_ITEM,
  332.                                 (PVOID) &mciSysinfoParms,
  333.                                 0);
  334.       if (ulError == 0L)
  335.          /* Get the device type ordinal value for further use. */
  336.          usDeviceTypeOpened = (USHORT)mciSysinfoQueryName.usDeviceOrd;
  337.    }
  338.    else
  339.    {
  340.       ShowError("error in opening device", ulError);
  341.       return (ulError);
  342.    }
  343.  
  344.    memset(&lpWaveOpen, 0, sizeof(lpWaveOpen));
  345.    lpWaveOpen.hwndCallback = (ULONG) 0;
  346.  
  347.    lpWaveOpen.usDeviceID   = (USHORT)  NULL; /* this is returned   */
  348.  
  349.    /**********************************************************************
  350.    * Specify the device type. The pszDeviceType is to be interpreted as  *
  351.    * the low-order word is a standard device type, and the high-order    *
  352.    * word is the ordinal index for the device. In other words we are     *
  353.    * explecitely trying to open the default device on the system. This   *
  354.    * gives the ability to load a non existing (untitled) audio file.     *
  355.    **********************************************************************/
  356.    lpWaveOpen.pszDeviceType = (PSZ) MAKEULONG(MCI_DEVTYPE_WAVEFORM_AUDIO,
  357.                                               usDeviceTypeOpened);
  358.  
  359.    /* send and receive in the same buf   */
  360.    lpWaveOpen.pszElementName = (PSZ) NULL;
  361.    lpWaveOpen.pszAlias = (PSZ) NULL;
  362.  
  363.    ulReturn = mciSendCommand((USHORT) 0,
  364.                              MCI_OPEN,
  365.                              MCI_WAIT | MCI_OPEN_TYPE_ID |
  366.                              MCI_OPEN_SHAREABLE | MCI_OPEN_ELEMENT,
  367.                              (PVOID) &lpWaveOpen,
  368.                              (USHORT) NULL);
  369.  
  370.    if (ulReturn != 0)
  371.    {
  372.       (void) ShowError("Error in Opening the device", ulReturn);
  373.       mciSendCommand((USHORT) usWaveId,
  374.                      MCI_CLOSE,
  375.                      MCI_WAIT,
  376.                      (PVOID) &mciGenericParms,
  377.                      0);
  378.       return  ulReturn;
  379.    }
  380.  
  381.    /* stash the returned device ID  */
  382.    usWaveId = lpWaveOpen.usDeviceID;
  383.  
  384.    /**************************************************************************/
  385.    /* * Set up parameters for the audio data file (such as stereo/mono,      */
  386.    /* sample * rate and sample size).                                        */
  387.    /**************************************************************************/
  388.    memset(&mciWaveSetParms, 0, sizeof(mciWaveSetParms));
  389.    mciWaveSetParms.usChannels = (USHORT) MONO;             /* specify MONO/STEREO */
  390.    mciWaveSetParms.ulSamplesPerSec = (ULONG) SAMPPERSEC;   /* used for waveform */
  391.    mciWaveSetParms.usBitsPerSample = (USHORT) BITSPERSAMP; /* bits per sample   */
  392.    ulReturn = mciSendCommand((USHORT) usWaveId,
  393.      MCI_SET,
  394.      MCI_WAIT | MCI_WAVE_SET_CHANNELS | MCI_WAVE_SET_SAMPLESPERSEC | MCI_WAVE_SET_BITSPERSAMPLE,
  395.      (PVOID) &mciWaveSetParms,
  396.      0);
  397.    if (ulReturn)
  398.    {
  399.       ShowError("Error in setting up wave format ", ulReturn);
  400.       return (ulReturn);
  401.    }
  402.  
  403.    /************************************************************************/
  404.    /*   Set up time format in miliseconds                                  */
  405.    /************************************************************************/
  406.    memset(&mciWaveSetParms, 0, sizeof(mciWaveSetParms));
  407.    mciWaveSetParms.ulTimeFormat = MCI_FORMAT_MILLISECONDS;
  408.    ulReturn = mciSendCommand((USHORT) usWaveId,
  409.                              MCI_SET,
  410.                              MCI_WAIT | MCI_SET_TIME_FORMAT,
  411.                              (PVOID) &mciWaveSetParms,
  412.                              0);
  413.    if (ulReturn)
  414.    {
  415.       ShowError("Error in setting up time format ", ulReturn);
  416.       return (ulReturn);
  417.    }
  418.  
  419.    memset(&mciSetPosParms, 0, sizeof(mciSetPosParms));
  420.    mciSetPosParms.hwndCallback = hwnd;
  421.    mciSetPosParms.ulUnits      = 100;
  422.    ulReturn = mciSendCommand((USHORT) usWaveId,
  423.                              MCI_SET_POSITION_ADVISE,
  424.                              MCI_WAIT | MCI_SET_POSITION_ADVISE_ON,
  425.                              (PVOID) &mciSetPosParms,
  426.                              0);
  427.    if (ulReturn)
  428.    {
  429.       ShowError("error in setting the position setting", ulReturn);
  430.       return (ulReturn);
  431.    }
  432.  
  433.    /***********************************************************************/
  434.    /* Set up input source - microphone.                                   */
  435.    /***********************************************************************/
  436.    memset(&mciConnectorParms, 0, sizeof(mciConnectorParms));
  437.    mciConnectorParms.ulConnectorType = MCI_MICROPHONE_CONNECTOR; /* microphone */
  438.    ulReturn = mciSendCommand((USHORT) usWaveId,
  439.                              MCI_CONNECTOR,
  440.                              MCI_WAIT | MCI_CONNECTOR_TYPE | MCI_ENABLE_CONNECTOR,
  441.                              (PVOID) &mciConnectorParms,
  442.                              0);
  443.    if (ulReturn)
  444.    {
  445.       ShowError("error in setting microphone as source", ulReturn);
  446.       return (ulReturn);
  447.    }
  448.  
  449.    memset(&mciConnectionParms, 0, sizeof(mciConnectionParms));
  450.    mciConnectionParms.ulConnectorType = MCI_WAVE_STREAM_CONNECTOR;
  451.    ulReturn = mciSendCommand((USHORT) usWaveId,
  452.                              MCI_CONNECTION,
  453.                              MCI_WAIT | MCI_QUERY_CONNECTION | MCI_CONNECTOR_TYPE,
  454.                              (PVOID) &mciConnectionParms,
  455.                              0);
  456.    if (ulReturn)
  457.    {
  458.       ShowError("error in getting amp id", ulReturn);
  459.       return (ulReturn);
  460.    }
  461.    usAmpId = mciConnectionParms.usToDeviceID;
  462.  
  463.    /**********************************************************************/
  464.    /* * Set the appropriate input level.                                 */
  465.    /**********************************************************************/
  466.    mciAmpSetParms.ulAudio = MCI_SET_AUDIO_ALL; /* all the channels.         */
  467.    mciAmpSetParms.ulLevel = (ULONG) 100;       /* set audio level.          */
  468.    ulReturn = mciSendCommand((USHORT) usAmpId,
  469.                              MCI_SET,
  470.                              MCI_WAIT | MCI_SET_AUDIO | MCI_AMP_SET_GAIN,
  471.                              (PVOID) &mciAmpSetParms,
  472.                              0);
  473.    if (ulReturn)
  474.    {
  475.       ShowError("error in setting the gain level", ulReturn);
  476.       return (ulReturn);
  477.    }
  478. }
  479.  
  480. /*****************************************************************************
  481. *                                                                            *
  482. *   Subroutine Name : mmsrvPlay                                              *
  483. *                                                                            *
  484. *   Function: Play the recorded audio data.                                  *
  485. *                                                                            *
  486. *   Parameters :  HWND hwnd of audio dialog window, INPUT                    *
  487. *                                                                            *
  488. *   MMPM/2 API: mciSendCommand                                               *
  489. *                                                                            *
  490. *   MMPM/s Message handled: MCI_PLAY                                         *
  491. *                                                                            *
  492. *****************************************************************************/
  493. LONG APIENTRY mmsrvPlay(HWND hwnd)
  494. {
  495.    ULONG          ulReturn;
  496.    MCI_PLAY_PARMS mciPlayParms;
  497.  
  498.    if ((ulReturn = mmsrvSetVolume(usLevel)) != 0)
  499.       return ulReturn;
  500.    memset(&mciPlayParms, 0, sizeof(mciPlayParms));
  501.    mciPlayParms.hwndCallback = (HWND) hwnd;
  502.    mciPlayParms.ulFrom = 0;
  503.    if (ulReturn = mciSendCommand((USHORT) usWaveId,
  504.                                  MCI_PLAY,
  505.                                  MCI_NOTIFY | MCI_FROM,
  506.                                  (PVOID) &mciPlayParms,
  507.                                  0L))
  508.    {
  509.       ShowError("error during playback no ", ulReturn);
  510.    }
  511.    return  ulReturn;
  512. }
  513.  
  514. /*****************************************************************************
  515. *                                                                            *
  516. *   Subroutine Name : mmsrvRecord                                            *
  517. *                                                                            *
  518. *   Function: Record the voice.                                              *
  519. *                                                                            *
  520. *   Parameters :  HWND hwnd of audio dialog window, INPUT                    *
  521. *                                                                            *
  522. *   MMPM/2 API: mciSendCommand                                               *
  523. *                                                                            *
  524. *   MMPM/s Message handled: MCI_SEEK, MCI_DELETE, MCI_RECORD                 *
  525. *                                                                            *
  526. *   Pseudo Code: Change the media position of device.                        *
  527. *                Remove any remaining data from device.                      *
  528. *                Start recording.                                            *
  529. *****************************************************************************/
  530. LONG APIENTRY mmsrvRecord(HWND hwnd)
  531. {
  532.   ULONG             ulReturn = 0;
  533.   MCI_RECORD_PARMS  mciRecordParms;    /* for MCI_RECORD */
  534.   MCI_GENERIC_PARMS mciGenericParms;
  535.   MCI_AMP_SET_PARMS mciAmpSetParms;    /* for MCI_SET, amp/mix devices      */
  536.   MCI_EDIT_PARMS    mciEditParms;
  537.   MCI_SEEK_PARMS    mciWaveSeekParms;
  538.  
  539.    /**************************************************************************/
  540.    /* * Set the Monitor on.                                                  */
  541.    /**************************************************************************/
  542.    memset(&mciWaveSeekParms, 0, sizeof(mciWaveSeekParms));
  543.    mciWaveSeekParms.ulTo = 0L;
  544.    ulReturn = mciSendCommand((USHORT) usWaveId,
  545.                              MCI_SEEK,
  546.                              MCI_TO_START | MCI_WAIT,
  547.                              (PVOID) &mciWaveSeekParms,
  548.                              (USHORT) NULL);
  549.    if(ulReturn)
  550.    {
  551.       ShowError("error in seeking ", ulReturn);
  552.       return(ulReturn);
  553.    }
  554.  
  555.    memset(&mciEditParms, 0, sizeof(mciEditParms));
  556.    mciEditParms.hwndCallback = (ULONG) NULL;
  557.    mciEditParms.ulFrom = 0L;
  558.    ulReturn = mciSendCommand((USHORT) usWaveId,
  559.                              MCI_DELETE,
  560.                              MCI_WAIT,
  561.                              (PVOID) &mciEditParms,
  562.                              (USHORT) NULL);
  563.  
  564.    if(ulReturn)
  565.    {
  566.       ShowError("error occured in deleting old recording ", ulReturn);
  567.       return(ulReturn);
  568.    }
  569.  
  570.    /**************************************************************************/
  571.    /* initialize MCI_RECORD_PARMS structure with the pertinent               */
  572.    /* information then issue an MCI_RECORD command via mciSendCommand.       */
  573.    /**************************************************************************/
  574.    memset(&mciRecordParms, 0, sizeof(mciRecordParms));
  575.    mciRecordParms.hwndCallback = hwnd;                 /* notify main window */
  576.    mciRecordParms.ulFrom = 0;
  577.  
  578.    ulReturn = mciSendCommand((USHORT) usWaveId,
  579.                              MCI_RECORD,
  580.                              MCI_NOTIFY | MCI_FROM | MCI_RECORD_OVERWRITE,
  581.                              (PVOID) &mciRecordParms,
  582.                              0);
  583.    if (ulReturn)
  584.    {
  585.       ShowError("error occured in recording ", ulReturn);
  586.       memset(&mciGenericParms, 0, sizeof(mciGenericParms));
  587.       mciSendCommand((USHORT) usWaveId,
  588.                      MCI_STOP,
  589.                      MCI_WAIT,
  590.                      (PVOID) &mciGenericParms,
  591.                      0);
  592.    }
  593.    return(ulReturn);
  594. }
  595.