www.pudn.com > zmodem.rar > fh.c


/*
 * Copyright 1995 Omen Technology Inc All Rights Reserved
 *  Demonstration of comms file handle sharing.
 */
#include 
#include 
#include 

HANDLE Dport;
DCB Dcb;

char *qargv[] = { "fh", "sub", "", 0};

main(argc, argv)
char **argv;
{
	int r, i,
	int fport = 0;
	HANDLE h;
	SECURITY_ATTRIBUTES sa;

	sa.nLength = sizeof(sa);
	sa.lpSecurityDescriptor = NULL;
	sa.bInheritHandle = 1;

	if (argc == 1) {
		Dport = CreateFile( "COM1", GENERIC_READ|GENERIC_WRITE,
		  0,
		  &sa,
		  OPEN_EXISTING, 0, NULL);
		if (Dport == INVALID_HANDLE_VALUE) {
			r = GetLastError();
			printf("Can't open COM1 error=%X\n", r);
			return (1);
		}
		printf("COM1 opened handle=%X\n", Dport);
	}

	for (i = 1; i<40; ++i) {
		Dcb.BaudRate = 0;
		h = (HANDLE) i;
		r = GetCommState( h, &Dcb);
		if (Dcb.BaudRate) {
			printf("Handle %2d Speed %d\n", i, Dcb.BaudRate);
			fport = i;
		}
	}
	if (fport == 0)
		printf("No com port handle found!\n");
	_fileinfo = 1;
	if (argc == 1) {
		printf("Spawning...");
		spawnvp(0, "fh", qargv);
		//system("fh sub");
		printf("Returned...");
	}
	Sleep(2500);
	return 0;
}