openintf.cpp
来自「WDM的驱动程序实例,可供自学开发WDM者参考,其是在VC和COMPUWARE下」· C++ 代码 · 共 51 行
CPP
51 行
// OpenByIntf.cpp - open device by device interface
// Copyright (c) 1998 Compuware Corporation
#define NOCRYPT // prevent attempt to include missing files
#define _INC_EXCPT // prevent excpt.h from being included
#include "stdlib.h"
#include "windows.h"
#include "winioctl.h"
#include "devintf.h" // DriverWorks
// OpenByInterface
//
// Opens the nth device found with the given interface class
HANDLE OpenByInterface(
const GUID* pClassGuid, // points to the GUID that identifies the interface class
DWORD instance, // specifies which instance of the enumerated devices to open
PDWORD pError // address of variable to receive error status
)
{
HANDLE hDev = INVALID_HANDLE_VALUE;
CDeviceInterfaceClass DevClass((GUID*)pClassGuid, pError);
if ( *pError == ERROR_SUCCESS )
{
CDeviceInterface DevInterface(&DevClass, instance, pError);
if ( *pError == ERROR_SUCCESS )
{
hDev = CreateFile(
DevInterface.DevicePath(),
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if ( hDev == INVALID_HANDLE_VALUE )
*pError = GetLastError();
}
}
return hDev;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?