WDM驱动AddDevice例程中指定设备名的问题
cyu02
2009-11-22 22:12
楼主
WDM模式的驱动程序,创建设备指定设备名有两种方式,一个是调用IoRegisterDeviceInterface,一个是在IoCreateDevice函数中指定设备名。我按照《windows驱动程序开发详解》中的HelloWDM的方式创建的驱动,编译可以通过,但是无法安装成功,安装后有个黄色叹号,并提示reboot。我知道开发中鼓励使用第一种方式,但是第二种方式为什么会出现这种问题呢?
代码如下:
status = IoCreateDevice(
DriverObject,
sizeof(DEVICE_EXTENSION),
&(UNICODE_STRING)devname,
FILE_DEVICE_DISK,
0,
FALSE,
&fdo);
if( !NT_SUCCESS(status))
{
return status;
}
PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION)fdo->DeviceExtension;
pdx->devName=devName;
KeInitializeEvent(&pdx->StoppingEvent,NotificationEvent,FALSE);
pdx->bStopping=FALSE;
pdx->NextStackDevice = IoAttachDeviceToDeviceStack(fdo, PhysicalDeviceObject);
在设备管理器/属性的设备状态中可以得到一个错误码。能帮助你分析一下错误原因。
引用: 引用 2 楼 beyondma 的回复:
普通WINDOWS的驱动目前不太火呵呵。
是相当不火啊,问个问题都少人问津
两段ddk里的关于IOCreateDeive()中关于device name 参数原文,以及microsoft 关于如何name a device driver, 相信看了你就释然了。
驱动开发还是很有qian途的。加油。
1. “DeviceName ()
Optionally points to a buffer containing a zero-terminated Unicode string that names the device object. The string must be a full path name.
Typically, only physical device objects (PDOs), which are created by PnP bus drivers, are named. PnP function drivers and filter drivers should not specify a DeviceName for a functional device object (FDO) or filter device object (filter DO). Naming an FDO or filter DO bypasses the PnP Manager's security. If a user-mode component needs a symbolic link to the device, the function or filter driver should register a device interface (see IoRegisterDeviceInterface ). If a kernel-mode component needs a legacy device name, the driver must name the FDO, but naming is not recommended. "
2."
IoCreateDevice can only be used to create an unnamed device object, or a named device object for which a security descriptor is set by an INF file. Otherwise, drivers must use IoCreateDeviceSecure to create named device objects.
"
你好像没有导出符号连接名啊:
UNICODE_STRING deviceNameUnicodeString;
RtlInitUnicodeString(&deviceNameUnicodeString, NT_DEVICE_NAME);
NTSTATUS status = STATUS_SUCCESS;
status = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION),
&deviceNameUnicodeString,FILE_DEVICE_UNKNOWN,
0, false, &FunctionDevice);
if (!NT_SUCCESS(status))
{
DT("%s IoCreateDevice VMouse failed", FUN);
return status;
}
UNICODE_STRING deviceLinkUnicodeString;
RtlInitUnicodeString(&deviceLinkUnicodeString, DOS_DEVICE_NAME);
status = IoCreateSymbolicLink(&deviceLinkUnicodeString, &deviceNameUnicodeString);
if (!NT_SUCCESS(status))
{
DT("%s IoCreateSymbolicLink VMouse failed", FUN);
if (FunctionDevice)
{
IoDeleteDevice(FunctionDevice);
return status;
}
}
引用: 引用 5 楼 figo_liu1008 的回复:
两段ddk里的关于IOCreateDeive()中关于device name 参数原文,以及microsoft 关于如何name a device driver, 相信看了你就释然了。
驱动开发还是很有qian途的。加油。
1. “DeviceName ()
Optionally points to a buffer containing a zero-terminated Unicode string that names the device object. The string must be a full path name.
Typically, only physical device objects (PDOs), which are created by PnP bus drivers, are named. PnP function drivers and filter drivers should not specify a DeviceName for a functional device object (FDO) or filter device object (filter DO). Naming an FDO or filter DO bypasses the PnP Manager's security. If a user-mode component needs a symbolic link to the device, the function or filter driver should register a device interface (see IoRegisterDeviceInterface ). If a kernel-mode component needs a legacy device name, the driver must name the FDO, but naming is not recommended. "
2."
IoCreateDevice can only be used to create an unnamed device object, or a named device object for which a security descriptor is set by an INF file. Otherwise, drivers must use IoCreateDeviceSecure to create named device objects.
"
多谢,多看看DDK确实很有帮助。
PNP模式的驱动不鼓励指定设备名,但有的书中也是说是可以指定的,这本书《windows驱动程序开发详解》就是如此,我怀疑是字符串的问题,或者如DDK中所说zero-terminated Unicode string 。
IoCreateDevice can only be used to create an unnamed device object:这句话不太明白,NT模式的驱动使用这中方式,是可以指定设备名的,不明白为什么是only by used.
引用: 引用 6 楼 jassonrose 的回复:
你好像没有导出符号连接名啊:
UNICODE_STRING? ? ? ? deviceNameUnicodeString;
RtlInitUnicodeString(&deviceNameUnicodeString, NT_DEVICE_NAME);
NTSTATUS status = STATUS_SUCCESS;
status = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION),
&deviceNameUnicodeString,FILE_DEVICE_UNKNOWN,
0, false, &FunctionDevice);
if (!NT_SUCCESS(status))
{
DT("%s IoCreateDevice VMouse failed", FUN);
return status;
}
UNICODE_STRING deviceLinkUnicodeString;
RtlInitUnicodeString(&deviceLinkUnicodeString, DOS_DEVICE_NAME);
status = IoCreateSymbolicLink(&deviceLinkUnicodeString, &deviceNameUnicodeString);
if (!NT_SUCCESS(status))
{
DT("%s IoCreateSymbolicLink VMouse failed", FUN);
if (FunctionDevice)
{
IoDeleteDevice(FunctionDevice);
return status;
}
}
不导出连接名不会出现这种问题的。
"
多谢,多看看DDK确实很有帮助。
PNP模式的驱动不鼓励指定设备名,但有的书中也是说是可以指定的,这本书《windows驱动程序开发详解》就是如此,我怀疑是字符串的问题,或者如DDK中所说zero-terminated Unicode string 。
IoCreateDevice can only be used to create an unnamed device object:这句话不太明白,NT模式的驱动使用这中方式,是可以指定设备名的,不明白为什么是only by used.
"
我的理解:这是microsoft关于它IoCreateDevce API的约定。
你用它这段话里的另一个IoCreateDeviceSecure 试一下。