“驱动小妹”
驱动牛犊
驱动牛犊
  • 注册日期2006-09-09
  • 最后登录2007-11-24
  • 粉丝0
  • 关注0
  • 积分770分
  • 威望78点
  • 贡献值0点
  • 好评度77点
  • 原创分0分
  • 专家分0分
阅读:1079回复:1

求救: IoCreateSymbolicLink(&win32Name, &ntName)

楼主#
更多 发布于:2007-08-09 14:28
我的 status = IoCreateSymbolicLink(&win32Name, &ntName)
为什么返回是错误的

UNICODE_STRING      ntName = RTL_CONSTANT_STRING(L"\\Device\\usbstorfilterDevice");
UNICODE_STRING      win32Name = RTL_CONSTANT_STRING(L"\\DosDevices\\usbstorfilterDevice");

首先我的过滤驱动是可以加载的,而且可以用。就是想跟应用程序通信。所以想用IoCreateSymbolicLink(&win32Name, &ntName)

过程:

status=IoCreateDevice(
        DriverObject,
        sizeof (DEVICE_EXTENSION),
        &ntName,
        FILE_DEVICE_DISK,
        FILE_DEVICE_SECURE_OPEN,
        FALSE,
        &deviceObject
        );
这个状态是正确的。


deviceExtension->NextLowerDriver=IoAttachDeviceToDeviceStack(                              deviceObject,                            PhysicalDeviceObject);

这个也是正确的。

status = IoCreateSymbolicLink(&win32Name, &ntName);
就这个是错误的。





oushengfen
驱动牛犊
驱动牛犊
  • 注册日期2007-06-28
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分747分
  • 威望124点
  • 贡献值1点
  • 好评度82点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2007-08-10 21:28
NTSTATUS
Ezusb_CreateDeviceObject(
    IN PDRIVER_OBJECT DriverObject,
    IN PDEVICE_OBJECT *DeviceObject,
    LONG Instance
    )
/*++

Routine Description:
    Creates a Functional DeviceObject

Arguments:
    DriverObject - pointer to the driver object for device
    DeviceObject - pointer to DeviceObject pointer to return
                   created device object.
    Instance - instnace of the device create.

Return Value:
    STATUS_SUCCESS if successful,
    STATUS_UNSUCCESSFUL otherwise
--*/
{
   NTSTATUS ntStatus;
   WCHAR deviceLinkBuffer[]  = L"\\DosDevices\\Ezusb-0";
   UNICODE_STRING deviceLinkUnicodeString;
   WCHAR deviceNameBuffer[]  = L"\\Device\\Ezusb-0";
   UNICODE_STRING deviceNameUnicodeString;
   PDEVICE_EXTENSION pdx;
   STRING deviceName;

   Ezusb_KdPrint(("enter Ezusb_CreateDeviceObject instance = %d\n", Instance));

   //
   // fix up device names based on Instance
   //
   deviceLinkBuffer[18] = (USHORT) ('0' + Instance);
   deviceNameBuffer[14] = (USHORT) ('0' + Instance);

   Ezusb_KdPrint(("Create Device name (%ws)\n", deviceNameBuffer));

   RtlInitUnicodeString (&deviceNameUnicodeString,
                         deviceNameBuffer);

   //
   //Print out the unicode string
   //NOTE:  We must first convert the string to Unicode due to a bug in the Debugger that does not allow
   //       Unicode Strings to be printed to the debug device.
   //
   deviceName.Buffer = NULL;

   ntStatus = RtlUnicodeStringToAnsiString (&deviceName,
                                          &deviceNameUnicodeString,
                                          TRUE);


   if (NT_SUCCESS(ntStatus))
   {
      Ezusb_KdPrint(("Create Device Name (%s)\n", deviceName.Buffer));
      RtlFreeAnsiString (&deviceName);
   }
   else
   {
      Ezusb_KdPrint(("Unicode to Ansi str failed w/ ntStatus: 0x%x\n",ntStatus));
   }

   ntStatus = IoCreateDevice (DriverObject,
                              sizeof (DEVICE_EXTENSION),
                              &deviceNameUnicodeString,
                              FILE_DEVICE_UNKNOWN,
                              0,
                              FALSE,
                              DeviceObject);


   if (NT_SUCCESS(ntStatus))
   {

      // Initialize our device extension
      pdx = (PDEVICE_EXTENSION) ((*DeviceObject)->DeviceExtension);

      RtlCopyMemory(pdx->DeviceLinkNameBuffer,
                   deviceLinkBuffer,
                   sizeof(deviceLinkBuffer));

      pdx->OpenHandles = 0;
      pdx->ConfigurationHandle = NULL;
      pdx->DeviceDescriptor = NULL;
      pdx->NeedCleanup = FALSE;
      pdx->DataRingBuffer = NULL;
      pdx->DescriptorRingBuffer = NULL;
      pdx->Started = FALSE;

      // Initialize our interface
      pdx->Interface = NULL;

      RtlInitUnicodeString (&deviceLinkUnicodeString,
                           deviceLinkBuffer);

      Ezusb_KdPrint(("Create DosDevice name (%ws)\n", deviceLinkBuffer));

      ntStatus = IoCreateSymbolicLink (&deviceLinkUnicodeString,
                                      &deviceNameUnicodeString);

   }

   Ezusb_KdPrint(("exit Ezusb_CreateDeviceObject (%x)\n", ntStatus));

   return ntStatus;
}


这个一个封装好的模块,直接可以使用,DriverObject->DriverExtension->AddDevice = Ezusb_PnPAddDevice;

   instance = 0;
   do
   {
      ntStatus = Ezusb_CreateDeviceObject(DriverObject, &deviceObject, instance);
      instance++;
   } while (!NT_SUCCESS(ntStatus) && (instance < MAX_EZUSB_DEVICES));

直接调用就可以了,绝对没问题,你的问题所在是要使用RtlUnicodeStringToAnsiString进行字符串转换.
游客

返回顶部