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

📄 eventapp.cpp

📁 武安河书第一版(vxd)Windows 驱动例子
💻 CPP
字号:
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <winioctl.h>
#include "event.h"

HANDLE	hDevice;
int i;

DWORD WINAPI SecondThread(PVOID hEventRing3)
{
	while(TRUE)	{
		WaitForSingleObject(hEventRing3,INFINITE);
		DeviceIoControl(hDevice,READ,0,0,&i,0,0,0);
		printf("%d\n", i);
	}
	return 0;
}

void main()
{
	HANDLE	hEventRing3,hEventRing0;
	HMODULE hKernel32Dll;
	DWORD tid;

	HANDLE (WINAPI *pfOpenVxDHandle)(HANDLE);
	hEventRing3=CreateEvent(0,FALSE,FALSE,NULL);
	if (!hEventRing3) {
    	fprintf(stderr,"Failed to create event3...\n");
		exit(1);
	}
	hKernel32Dll=LoadLibrary("kernel32.dll");
	if (!hKernel32Dll) {
    	fprintf(stderr, "Failed to load...\n");
		exit(1);
	}
	pfOpenVxDHandle=(HANDLE(WINAPI *)(HANDLE))GetProcAddress(hKernel32Dll,"OpenVxDHandle");
	if (!pfOpenVxDHandle) {
    	fprintf(stderr, "Failed to get...\n");
		exit(1);
	}
	hEventRing0=(HANDLE)(*pfOpenVxDHandle)(hEventRing3);
	if (!hEventRing0) {
    	fprintf(stderr, "Failed to get hEventRing0...\n");
		exit(1);
	}

	hDevice=CreateFile("\\\\.\\MOUSE.VXD",0,0,0,CREATE_NEW,FILE_FLAG_DELETE_ON_CLOSE,0);
	if (hDevice == INVALID_HANDLE_VALUE) {
        fprintf(stderr,"Cannot load VxD,error=%08ld\n",GetLastError());
	 	exit(1);
	}
	if ( !DeviceIoControl(hDevice,hEventPASS,hEventRing0,0,0,0,0,0)) {
    	fprintf(stderr, "Failed to pass hEvent...\n");
		exit(1);
	}

	CreateThread(0,0x1000,SecondThread,hEventRing3,0,&tid);
	printf("press any key to exit . . .\n");
	getch();
	CloseHandle(hDevice);
}

⌨️ 快捷键说明

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