⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ioproc.cpp

📁 用VC编写的设备通讯程序,里面有很多规约,自己下载
💻 CPP
字号:
// ioproc.cpp : Defines the class behaviors for the application.
//

#define _WIN32_WINNT 0x0400

/*
 * NT Definitions
 */
#include <windows.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "gencmr.h"
#include "cmriosrv.h"

#define WAITINGTIME		200
#define ONE_SECONDS		1000

static HANDLE timHandle, wakeEvt;

VOID CALLBACK actPollSchedFunc(LPVOID, DWORD, DWORD);
/////////////////////////////////////////////////////////////////////////////

void main( int argc, char *argv[] )
{
	int    parentPid;
	DWORD  nExtCode;
	HANDLE hParent;
	LARGE_INTEGER timPeriod;

	if( argc < 2) {							// if no arguments passed
		RecordMsg(__LINE__, "Could not start without initialize parameter, exit...", 0 );
		ExitProcess( 0 );
	}
	else {
		parentPid = atoi( argv[1] );		// pass the argument passed
		hParent = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, parentPid);
	}

	wakeEvt = ::CreateEvent(NULL, TRUE, FALSE, NULL);
	if ( wakeEvt == NULL ) {
		RecordMsg(__LINE__, "Could not create wake event, exit...", GetLastError() );
		ExitProcess( 0 );
	}

	CreIoSystem("TIMCOMM", wakeEvt, FALSE);

	// create i/o waitable timer
	timPeriod.QuadPart = -ONE_SECONDS * 10000;
	timHandle = ::CreateWaitableTimer(NULL, TRUE, NULL);
	if ( timHandle == NULL ) {
		RecordMsg(__LINE__, "Could not create waitable timer, exit...", GetLastError() );
		ExitProcess( 0 );
	}

	if (!(argc >= 3 && strcmp(argv[2], "debug") == 0)) {	
		// register to system process manager
		RegIoSystem();
	}

	// connect to i/o ports
	CreIoDevice(hParent);

	// startup i/o waitable timer
	::SetWaitableTimer(timHandle, &timPeriod, ONE_SECONDS, actPollSchedFunc, NULL, FALSE);

	for (;;) {

		// check process operation status
		if (GetExitSignal())
			break;

		// check system operation status
		if (!GetExitCodeProcess(hParent, &nExtCode) ||
			 nExtCode != STILL_ACTIVE)
			break;

		// waiting process task
		WaitForSingleObjectEx(wakeEvt, WAITINGTIME, TRUE);

		// process i/o request
		MngrService();
	}

	// release system resource
	::CloseHandle(wakeEvt);
	::CloseHandle(timHandle);
	ClsIoSystem();
}

VOID CALLBACK actPollSchedFunc(LPVOID ptr, DWORD dw1, DWORD dw2)
{
	ChkPollSche();
	::PulseEvent(wakeEvt);

	return;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -