How to open control object from user app using symbolic link?

Discussion in 'Windows Vista Drivers' started by dmitrym_10, Aug 21, 2007.

  1. dmitrym_10

    dmitrym_10 Guest

    Hi There,

    I am having problem opening control device object that I create in driver
    from the user application.
    I create a control object and make a symbolic link to it. When I try to open
    it using CreateFile() it returns invalid handle and GetlastError() returns
    "file not found"

    Here is how I create control object:

    #define K_MOUSE_FILTER_DEVICE_NAME L"\\Device\\MyCompanyMouseSniffer"
    #define K_MOUSE_CONTROL_DEVICE_NAME L"\\Device\\MyCompanyMouseSnifferIoCtl"

    MouseFilter_CreateControlObject(IN WDFDRIVER Driver)
    UNICODE_STRING DeviceName;
    WDF_OBJECT_ATTRIBUTES DeviceAttributes;
    WDF_IO_QUEUE_CONFIG DeviceQueueConfig;
    WDFQUEUE DeviceQueue;
    UNICODE_STRING SymbolicLinkName;


    if (InstanceNo != 0)
    return STATUS_SUCCESS;

    /* Allocate INIT structure. */
    DeviceInit = WdfControlDeviceInitAllocate(Driver,
    if (NULL == DeviceInit)
    DebugPrint(("WdfControlDeviceInitAllocate failed\n"));
    return status;

    /* Assign name to the control device. */
    RtlInitUnicodeString(&DeviceName, K_MOUSE_FILTER_DEVICE_NAME);
    status = WdfDeviceInitAssignName(DeviceInit, &DeviceName);
    if (!NT_SUCCESS(status))
    DebugPrint(("WdfDeviceInitAssignName failed with status code
    0x%x\n", status));
    return status;

    /* Shutdown notification must be set before WdfDeviceCreate() call. */
    ControlDevice_EvtShutdown, WdfDeviceShutdown);

    /* Initialize attributes struct. */

    /* Create device. */
    status = WdfDeviceCreate(&DeviceInit, &DeviceAttributes, &ControlObject);
    if (!NT_SUCCESS(status))
    DebugPrint(("WdfDeviceCreate failed with status code 0x%x\n",
    return status;

    /* Create device queue. */
    DeviceQueueConfig.EvtIoRead = ControlObject_EvtIoRead; // READ ONLY
    status = WdfIoQueueCreate(ControlObject, &DeviceQueueConfig,
    if (!NT_SUCCESS(status))
    DebugPrint(("WdfIoQueueCreate failed with status code 0x%x\n",
    return status;

    /* Create symbolic link so it could be open by CreateFile() from user
    space. */
    RtlInitUnicodeString(&SymbolicLinkName, K_MOUSE_CONTROL_DEVICE_NAME);
    status = WdfDeviceCreateSymbolicLink(ControlObject, &SymbolicLinkName);
    if (!NT_SUCCESS(status))
    DebugPrint(("WdfDeviceCreateSymbolicLink failed with status code
    0x%x\n", status));
    return status;

    /* Done. */

    InstanceNo ++;

    return status;

    It doesn't fail and function return status 0.

    Here is how I open it from user application:
    PWCHAR path = L"\\\\.\\MyCompanyMouseSnifferIoCtl";
    HANDLE device = CreateFile(path, 0, FILE_SHARE_READ | FILE_SHARE_WRITE,

    I also tried L"\\Device\\MyCompanyMouseSnifferIoCtl";

    I can't figure out what I am doing wrong. I appreciate your help.
    Thank you,
    dmitrym_10, Aug 21, 2007
    1. Advertisements

  2. dmitrym_10

    dmitrym_10 Guest

    I have figured it out.

    Device must me named with NT device name
    #define K_MOUSE_FILTER_DEVICE_NAME L"\\Device\\MyCompanyMouseSniffer"

    And if symbolic link uses Dos device name
    #define K_MOUSE_FILTER_DEVICE_NAME L"\\Device\\MyCompanyMouseSniffer"

    It all works and I can open it from user application with CreateFile().
    dmitrym_10, Aug 21, 2007
    1. Advertisements

  3. change
    #define K_MOUSE_CONTROL_DEVICE_NAME L"\\??\\MyCompanyMouseSnifferIoCtl"

    also, look at the KMDF kbdfiltr example which enumerates a raw PDO. it is
    much easier to manage then a control object if there is more then one mouse

    Doron Holan [MSFT], Aug 21, 2007
  4. When we looked at raw PDOs (versus control devices), my colleague
    basically reported that the OS behavior was different in each of 2K,
    XP, and Vista. In some cases you got the hardware wizard (or at least
    the balloon tip), in some cases you needed a skeleton INF to install
    the PDO, and so on. Is that still the case or did we do something
    chris.aseltine, Aug 21, 2007
  5. Yes you have to provide a NULL INF on Win2K to get the raw PDO instantiated.
    I don't remember whether the balloon tip comes up on XP and above. My
    feeling is that it does.
    Eliyas Yakub [MSFT], Aug 21, 2007
  6. you need the INF for win2k, i think we accidentally left that iNF out of the
    WDK and it will be in the next wdk. yes, there are differences but i don't
    really see why that is a showstopper if you have the appropriate INF. IMHO,
    the 1:1 relationship for raw PDo to mouse is much better then the 1:N
    relationship you have with a control device.

    Doron Holan [MSFT], Aug 22, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.