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

📄 test_filethread.cpp

📁 驱动程序中的文件读写。
💻 CPP
字号:
#include <stdio.h>
#include <conio.h>
#include <windows.h>

#include <winioctl.h>
#include "..\FileThreadioctl.h"

#include "..\FileThreadDeviceinterface.h"	// Has class GUID definition

// This function is found in module OpenByIntf.cpp
HANDLE OpenByInterface(GUID* pClassGuid, DWORD instance, PDWORD pError);

// Class GUID used to open device
//
GUID ClassGuid = FileThreadDevice_CLASS_GUID;

ULONG inchar(PUCHAR buffer);
void outchar(PUCHAR buffer);

////////////////////////////////////////////////////////////////////////
// Main entry point
//
//
int __cdecl main(int argc, char *argv[])
{
	DWORD	Error;
	HANDLE	hDevice;
	BOOLEAN status;
	UCHAR buffer[32];	
	ULONG nReturned;
	ULONG i;

	printf("Test application Test_FileThread starting...\n");

	hDevice = OpenByInterface( &ClassGuid, 0, &Error);
	if (hDevice == INVALID_HANDLE_VALUE)
	{
		printf("ERROR opening device: (%0x) returned from CreateFile\n", GetLastError());
		exit(1);
	}
	else
	{
		printf("Device found, handle open.\n");
	}

	i=inchar(buffer);
	memset(buffer, 0, sizeof(buffer));

// Read the file
	status = DeviceIoControl(hDevice,
		FILETHREAD_IOCTL_800,
		&i,
		sizeof(ULONG),
		buffer,
		sizeof(buffer),
		&nReturned,
		NULL);
	if (! status )
	{
		printf("DeviceIoControl call to read failed: %x\n", GetLastError());
		exit(1);
	}
	else if (nReturned != 32) {
		printf("Data is only read %d bytes\n",nReturned);
		exit(1);
	}
	outchar(buffer);

	CloseHandle(hDevice);
	return 0;
}
ULONG inchar(PUCHAR buffer)
{
	ULONG i;
	UCHAR *pbuf;
	printf("请输入汉字:"); 
	pbuf=buffer;
l1:	*pbuf=_getch();
	if ((*pbuf&0x80)==0) goto l1;
	pbuf+=1;
	*pbuf=_getch();
	_putch(*--pbuf);
	_putch(*++pbuf);
	printf("\n"); 
	i=(*--pbuf - 0xa1)*94;
	i=i+(*++pbuf - 0xa1);
	i=i*32;
	return i;
}
void outchar(PUCHAR buffer)
{
	int j,jj;
	UCHAR *pbuf,c;

	pbuf=buffer;
	for (j=0;j<16;j++)
	{
		c=*pbuf++;
		for (jj=0;jj<8;jj++)
		{
			if ((c&0x80) == 0) printf(" ");
			else printf("O");
			c=c << 1;
		}
		c=*pbuf++;
		for (jj=0;jj<8;jj++)
		{
			if ((c&0x80) == 0) printf(" ");
			else printf("O");
			c=c << 1;
		}
		printf("\n"); 
	}
}

⌨️ 快捷键说明

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