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

📄 cons.c

📁 wince host 和 target PCI驱动程序
💻 C
字号:
/*
COPYRIGHT (c) 1996 by Philips Semiconductors

THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED AND COPIED IN 
ACCORDANCE WITH THE TERMS AND CONDITIONS OF SUCH A LICENSE AND WITH THE 
INCLUSION OF THE THIS COPY RIGHT NOTICE. THIS SOFTWARE OR ANY OTHER COPIES 
OF THIS SOFTWARE MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER
PERSON. THE OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED. 

THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT ANY PRIOR NOTICE
AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY Philips Semiconductor. 

PHILIPS ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE
ON PLATFORMS OTHER THAN THE ONE ON WHICH THIS SOFTWARE IS FURNISHED.
*/
/*
	Copyright (c) 1996 Philips Semiconductors - TriMedia. All rights reserved.

FILE	cons.c

HISTROY
		#define	TR Tilakraj Roy
		950221	TR Created 
*/

#include "windows.h"
#include "conio.h"
#include "stdio.h"

/* private includes */
#include "stdcom.h"
#include "cons.h"

CONS_VTBL ConsVtbl =
{
	consCreate,
	consDestroy,
	consOpen,
	consClose,
	consReadChar,
	consWriteChar,
	consWriteStr,
	consGetHandles
};


BOOL	consCreate ( INTERFACE_ID RefIID, PVOID *pObject )
{
	PCONS_OBJECT	this;

	if ( *pObject == NULL )
	{
		if ( ( this = malloc ( sizeof ( CONS_OBJECT ) ) ) == NULL )
		{	
			*pObject = NULL;
			return FALSE;
		}
		else
		{
			this->pvRef = this;
			if ( QueryInterface ( RefIID, &this->pVtbl ) == FALSE )
			{
				free (this);	
				return FALSE;
			}
			*pObject = this;
			return TRUE;
		}
	}
	else
	{
		this = (PCONS_OBJECT)*pObject;
		this->pvRef = this;
		if ( QueryInterface ( RefIID, &this->pVtbl ) == FALSE )
		{
			free (this);	
			return FALSE;
		}
		// create all the base class instances.
		return TRUE;
	}
}

BOOL	consDestroy ( PVOID pObject )
{
	PCONS_OBJECT	this = (PCONS_OBJECT)pObject;
	if ( this->pvRef != this )
		return FALSE;
	free ( this );
}

BOOL	consOpen(PVOID pObject )
{
	PCONS_OBJECT this = (PCONS_OBJECT)pObject;
	DWORD	Mode;

	#if 1
	this->hStdin = GetStdHandle ( STD_INPUT_HANDLE );
	this->hStdout = GetStdHandle ( STD_OUTPUT_HANDLE );
	this->hStderr = GetStdHandle ( STD_ERROR_HANDLE );
	/* turn echoing & line buffering off */
	GetConsoleMode ( this->hStdin, &Mode  );
	Mode &=
		~( ENABLE_LINE_INPUT |  ENABLE_ECHO_INPUT );
	SetConsoleMode ( this->hStdin, Mode  );

	#else
	setbuf ( stdin, NULL);
	#endif
	return  TRUE;

}

VOID	consClose(PVOID pObject)
{

}

BOOL	consReadChar(PVOID pObject, PVOID pBuffer, DWORD dwLength)
{
	PCONS_OBJECT this = (PCONS_OBJECT)pObject;
	#if 1
	DWORD	dwBytesRead;
	ReadFile ( this->hStdin, pBuffer, dwLength, &dwBytesRead, NULL );
	#else
	*(PCHAR)pBuffer = getchar()	;
	#endif
	return TRUE;
}

BOOL	consWriteChar(PVOID pObject, PVOID pBuffer, DWORD dwLength)
{
	PCONS_OBJECT this = (PCONS_OBJECT)pObject;
	#if 1
	DWORD	dwBytesWritten;
	WriteFile ( this->hStdout, pBuffer, dwLength, &dwBytesWritten, NULL );
	#else
	PCHAR	pChar = (PCHAR)pBuffer;
	while ( dwLength -- )putchar ( *pChar++ );
	#endif
	return TRUE;
}

BOOL	consWriteStr (PVOID pObject, PSTR pszString)
{
	PCONS_OBJECT this = (PCONS_OBJECT)pObject;
	return  this->pVtbl->WriteChar ( this, pszString, strlen (pszString) );
}

VOID	consGetHandles (PVOID pObject,
	HANDLE *phIn, HANDLE *phOut, HANDLE *phErr)
{
	PCONS_OBJECT this = (PCONS_OBJECT)pObject;

	*phIn = this->hStdin;
	*phOut = this->hStdout;
	*phErr = this->hStderr;
}

⌨️ 快捷键说明

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