CDeviceInterfaceClass,CDeviceInterface类:
【在应用程序级上使用设备接口】
DriverWorks提供了这两个类用来支持设备接口在应用程序中的访问。这两个类的声明和实现在devintf.h中。
CDeviceInterfaceClass类封装了一个设备信息集合(set),这个set包含了所有关于一个具体类的设备接口信息。
应用程序可以使用一个CDeviceInterfaceClass类的实例来包含一个或多个CDeviceInterface类的实例。
CDeviceInterface类抽象了一个单一设备接口,它的成员函数DevicePath()可以返回一个指向设备路径名的指针,
这个指针可以作为CreateFile的参数来打开一个设备句柄。
以下是一个最基本的应用例子的模板:
extern GUID TestGuid;
HANDLE OpenByInterface(
GUID* pClassGuid,
DWORD instance,
PDWORD pError
)
{
CDeviceInterfaceClass DevClass(pClassGuid, pError);
if (*pError != ERROR_SUCCESS)
return INVALID_HANDLE_VALUE;
CDeviceInterface DevInterface(&DevClass, instance, pError);
if (*pError != ERROR_SUCCESS)
return INVALID_HANDLE_VALUE;
cout << "The device path is "
<< DevInterface.DevicePath()
<< endl;
HANDLE hDev;
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;
}
一些简单的驱动测试程序可以直接使用这段代码(使用自己的GUID)。
声明GUID示例:
static GUID TestGuid =
{ 0x4747be20, 0x62ce, 0x11cf, { 0xd6, 0xa5, 0x28, 0xdb, 0x04, 0xc1, 0x00, 0x00 } };
----------------
§ 译自"DriverWorks帮助文件" §
§ 李文凯 2008年03月20日 §
----------------