home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / windows / c / wmseri / wnotify.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-05  |  1.7 KB  |  66 lines

  1. //
  2. //     W M S E R I A L - Windows Modem Example
  3. //
  4. // This is only part of a multiple source project.  To build the
  5. // executable please use the makefile provided or construct
  6. // a project file containing the files and settings listed in
  7. // PROJECT.TXT.
  8. //
  9. // Remember to modify the directories to reflect your configuration.
  10. //
  11. //                                                     - J A A
  12.  
  13. // WNOTIFY.C
  14.  
  15. #include <windows.h>
  16. #include "wmserial.h"
  17.  
  18.  
  19. int ProcessCommNotify(HWND hWnd, int nComID, int nNotification)
  20.    {
  21.    HANDLE hBufferMem;
  22.    LPSTR szData;
  23.    int nResult;
  24.  
  25.    // Process Receive Notice    
  26.    if ( nNotification & CN_RECEIVE )
  27.        {
  28.        // Get memory for data
  29.        hBufferMem = GlobalAlloc( GMEM_MOVEABLE, QBUFFSIZE );
  30.        if (!hBufferMem)
  31.            {
  32.            MessageBeep(MB_ICONEXCLAMATION);
  33.            MessageBox(hWnd,"Not enough memory for initializing modem.","Example Windows Terminal",MB_ICONSTOP);
  34.            PostMessage(hWnd,WM_CLOSE,0,0L);
  35.            return NULL;
  36.            }
  37.        szData = (LPSTR) GlobalLock(hBufferMem);
  38.  
  39.        nResult = ReadComPort ( nComID, szData, QBUFFSIZE-1 );
  40.        if (nResult > 0)
  41.            {
  42.            szData[nResult] = 0;
  43.            TTYWriteScreen(szData);
  44.            }
  45.        else if (nResult < 0)
  46.            {
  47.            szData[-nResult] = 0;
  48.            TTYWriteScreen(szData);
  49.            GlobalUnlock(hBufferMem);       
  50.            return nResult;
  51.            }
  52.        GlobalUnlock(hBufferMem);
  53.        CheckComPort(nComID,NULL);
  54.        }
  55.  
  56.  
  57.    // Process Transmit Notice
  58.    if ( nNotification & CN_TRANSMIT )
  59.        nResult = WriteComPort(nComID, NULL, NULL);
  60.        // Last Error is left for CheckComPort() call
  61.  
  62.  
  63.    return nResult;
  64.    }
  65.  
  66.