test.cpp

来自「配置PCI配置空间的驱动程序源代码」· C++ 代码 · 共 57 行

CPP
57
字号
#include "stdafx.h"
#include <winioctl.h>
#include <conio.h>
#include <tchar.h>
#include "install.h"
#include "..\sys\ioctls.h"

int main(int argc, char* argv[])
{
	int i;
	char szFullPathName[255];
	
	unsigned long PCIBuses[16];
	unsigned long PCIBuffer[2];
	int Bus, Device;

	GetCurrentDirectory(255, szFullPathName);
	strcat(szFullPathName, "\\PCIConf.inf");
	printf("%s\n", szFullPathName);
	i=InstallDriver(szFullPathName, _T("*WCO0904"));
	printf("InstallDriver = %d\n", i);
	HANDLE hdevice = CreateFile("\\\\.\\PCICONF", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
	if (hdevice == INVALID_HANDLE_VALUE)
	{
		printf("Unable to open IOCTL device - error %d\n", GetLastError());
		return 1;
	}
	DWORD junk;
	
	for(Bus=0; Bus<5; Bus++)
	{
		for(Device=0; Device<32; Device++)
		{
			PCIBuses[0]=Bus;
			PCIBuses[1]=Device;

			DeviceIoControl(hdevice, IOCTL_GET_PCI_BUF, PCIBuses, sizeof(unsigned int)*2, PCIBuffer, sizeof(unsigned long)*16, &junk, NULL);
			if(junk>5)
			{
				printf("\nBus=%x\tDevice=%x\n", Bus, Device);
				for(i=0; i<16; i++)
					printf("%x : %8lx\n", i, PCIBuffer[i]);
			}
		}
	}
	
	getch();

	CloseHandle(hdevice);
	i=RemoveDriver(_T("*WCO0904"));
	printf("RemoveDriver = %d\n", i);
	printf("Game Over!\n");
	printf("Press any key to exit...\n");
	getch();
	return 0;
}

⌨️ 快捷键说明

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