win32app.c

来自「共34个各种VxD的源代码」· C语言 代码 · 共 52 行

C
52
字号
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include "dmabuf.h"

HANDLE		hDevice;
DMA_BUFFER_DESCRIPTOR dmadesc;	

void main(int ac, char* av[])
{
	DWORD   cbBytesReturned;
	DWORD	err;

	const PCHAR VxDName = "\\\\.\\DMABUF.VXD";
	hDevice = CreateFile(VxDName, 0,0,0,
                        CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0);

	if (hDevice == INVALID_HANDLE_VALUE)
	{
		err = GetLastError();
       	fprintf(stderr, "Cannot load VxD, error=%08lx\n", err );
		if (err == ERROR_NOT_SUPPORTED)
		{
			DeleteFile("\\\\.\\DMABUF");
		}
	 	exit(1);
	}


	dmadesc.Size = 32 * 1024;
	if (!DeviceIoControl(hDevice, DMABUF_FUNC_ALLOCBUFFER,
               &dmadesc, sizeof(DMA_BUFFER_DESCRIPTOR), 
               NULL, 0, &cbBytesReturned, NULL))
   {
		printf("DeviceIoControl failed, error=%d\n", GetLastError() );
   }
	else
	{
		printf( "Physical=%08lX\nLinear=%08lX\n", dmadesc.PhysAddr, dmadesc.LinAddr );
		if (!DeviceIoControl(hDevice, DMABUF_FUNC_FREEBUFFER,
    	           &dmadesc, sizeof(DMA_BUFFER_DESCRIPTOR), 
        	       NULL, 0, &cbBytesReturned, NULL)
		   )
      {
			printf("DeviceIoControl failed, error=%d\n", GetLastError() );
		}
	}

	CloseHandle( hDevice );
}

⌨️ 快捷键说明

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