home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Microsoft Programmer's Library 1.3
/
Microsoft-Programers-Library-v1.3.iso
/
sampcode
/
win_lrn
/
comm
/
closecom.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-08-10
|
5KB
|
166 lines
/*
*
* CloseComm
*
* This program demonstrates the use of the function CloseComm.
* This function closes the communication device specified by the
* parameter and frees any memory allocated for the device's transmit
* and receive queues. All characters in the output queue are sent
* before the communication device is closed.
*
* Other references: CFDial.c
*/
/*************************************************************************/
/* INCLUDE FILES */
/*************************************************************************/
#include <windows.h>
/*************************************************************************/
/* STRUCTURE DEFINTIONS */
/*************************************************************************/
typedef struct
{
int nDummy;
}
SETUPDATA;
/*************************************************************************/
/* GLOBAL VARIABLES */
/*************************************************************************/
static SETUPDATA strSetUpData;
static HANDLE hInst;
static char szFileName[] = "closecom";
static char szFuncName[] = "CloseComm";
/*************************************************************************/
/* FORWARD REFERENCES */
/*************************************************************************/
long FAR PASCAL WindowProc ( HANDLE , unsigned , WORD , LONG );
/*************************************************************************/
/* MAIN PROCEDURE */
/*************************************************************************/
int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
HANDLE hInstance, hPrevInstance;
LPSTR lpszCmdLine;
int cmdShow;
{
MSG msg;
WindowInit (hInstance, hPrevInstance, cmdShow );
while ( GetMessage((LPMSG)&msg, NULL, 0 , 0 ))
{
TranslateMessage((LPMSG)&msg);
DispatchMessage((LPMSG)&msg);
}
exit(msg.wParam);
}
/*************************************************************************/
/* INITIALIZATION */
/*************************************************************************/
BOOL WindowInit (hInstance , hPrevInstance , cmdShow)
HANDLE hInstance, hPrevInstance;
int cmdShow;
{
HWND hWnd;
if ( !hPrevInstance )
{
WNDCLASS rClass;
rClass.style = CS_HREDRAW | CS_VREDRAW;
rClass.lpfnWndProc = WindowProc;
rClass.cbClsExtra = 0;
rClass.cbWndExtra = 0;
rClass.hInstance = hInstance;
rClass.hCursor = LoadCursor ( NULL , IDC_ARROW );
rClass.hIcon = LoadIcon ( hInstance, IDI_APPLICATION );
rClass.hbrBackground = GetStockObject ( WHITE_BRUSH );
rClass.lpszMenuName = (LPSTR) NULL;
rClass.lpszClassName = (LPSTR) szFileName;
RegisterClass ( ( LPWNDCLASS ) &rClass );
}
else
GetInstanceData ( hPrevInstance, (PSTR) &strSetUpData,
sizeof ( SETUPDATA ) );
hInst = hInstance;
hWnd = CreateWindow ( (LPSTR) szFileName, (LPSTR) szFuncName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
(HWND) NULL, (HMENU) NULL,
(HANDLE) hInstance, (LPSTR) NULL );
ShowWindow ( hWnd , cmdShow );
UpdateWindow (hWnd);
return TRUE;
}
/*************************************************************************/
/* WINDOW PROCEDURE - PROCESS MESSAGES */
/*************************************************************************/
long FAR PASCAL WindowProc (hWnd , message , wParam , lParam)
HWND hWnd;
unsigned message;
WORD wParam;
LONG lParam;
{
PAINTSTRUCT ps;
switch (message)
{
case WM_PAINT:
BeginPaint ( hWnd, (LPPAINTSTRUCT)&ps );
FunctionDemonstrated ( );
EndPaint ( hWnd, (LPPAINTSTRUCT)&ps );
break;
case WM_DESTROY:
PostQuitMessage ( 0 );
break;
default:
return ( DefWindowProc ( hWnd , message , wParam , lParam ) );
break;
}
return ( 0L );
}
/*************************************************************************/
/* FUNCTION DEMONSTRATED HERE - LOOK HERE */
/*************************************************************************/
FunctionDemonstrated ( )
{
int nCid;
int nResult;
nCid = OpenComm ( ( LPSTR ) "LPT1", 255, 256 );
MessageBox ( NULL, ( LPSTR ) "Closing LPT1", ( LPSTR ) szFuncName, MB_OK );
nResult = CloseComm ( nCid );
if ( nResult == 0 )
MessageBox (NULL, (LPSTR)"LPT1 closed", (LPSTR)szFuncName, MB_OK);
else
MessageBox (NULL, (LPSTR)"LPT1 not closed", (LPSTR)szFuncName, MB_OK);
return TRUE;
}