WdfDeviceCreateSymbolicLink

This is probably a dumb question but how can I create multiple symbolic links. I only need one per device but I want multiple devices.

Right now I’m using:
DECLARE_CONST_UNICODE_STRING(dosDeviceName, L"\DosDevices\Driver0");
and
status = WdfDeviceCreateSymbolicLink(device, &dosDeviceName);

How can I make it such that every call to EvtDeviceAdd uses a different index on the end of Driver - ‘n’? I’ve seen a version in a WDM driver using a static variable for the device number but I can’t get that to work in WDF.

> ----------

From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of xxxxx@yahoo.com[SMTP:xxxxx@yahoo.com]
Reply To: Windows System Software Devs Interest List
Sent: Friday, January 25, 2008 2:16 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] WdfDeviceCreateSymbolicLink

How can I make it such that every call to EvtDeviceAdd uses a different index on the end of Driver - ‘n’? I’ve seen a version in a WDM driver using a static variable for the device number but I can’t get that to work in WDF.

What’s the problem? Global variable and InterlockedIncrement() should work as well as for WDM driver. But why do not use device interface, instead? The way you’re trying to use is obsolete and I’d even say it is dumb if you have multiple devices.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]

The same logic works in KMDF, there is no functional difference here between kmdf and wdm in how to format a string

ULONG g_Count = 0;
#define SYMLINK_NAME L"\DosDevices\Driver"
// support for 1000 links, XXX is a placeholder for 0-999
// this actually gives you one extra character b/c sizeof(string constant) will include the null in the size
#define SYMLINK_BUFFER_LENGTH (sizeof(SYMLINK_NAME L"XXX")/sizeof(WCHAR))

AddDevice()
{
DECLARE_UNICODE_STRING_SIZE(symlink, SYMLINK_BUFFER_LENGTH);
NTSTATUS status = RtlUnicodeStringPrintf(&symlink, SYMLINK_NAME L"%d", InterlockedIncrement(&g_Count));

}

You could make above code allocate the string buffer to make sure you can support an infinite number of links if you want to make your life more complicated…

D

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com
Sent: Thursday, January 24, 2008 5:17 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] WdfDeviceCreateSymbolicLink

This is probably a dumb question but how can I create multiple symbolic links. I only need one per device but I want multiple devices.

Right now I’m using:
DECLARE_CONST_UNICODE_STRING(dosDeviceName, L"\DosDevices\Driver0");
and
status = WdfDeviceCreateSymbolicLink(device, &dosDeviceName);

How can I make it such that every call to EvtDeviceAdd uses a different index on the end of Driver - ‘n’? I’ve seen a version in a WDM driver using a static variable for the device number but I can’t get that to work in WDF.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

I don’t know how to embed the variable into DECLARE_CONST_UNICODE_STRING(dosDeviceName, L"\DosDevices\Driver0");
and what is the new method?

>I don’t know how to embed the variable into

DECLARE_CONST_UNICODE_STRING(dosDeviceName, L"\DosDevices\Driver0");
You can use RtlUnicodeStringPrintf as Doron showed in his post.

and what is the new method?
Instead of symbolic link, applications can also use device interfaces to
access a device. The WdfDeviceCreateDeviceInterface lets you create an
interface.

wrote in message news:xxxxx@ntdev…
>I don’t know how to embed the variable into
>DECLARE_CONST_UNICODE_STRING(dosDeviceName, L"\DosDevices\Driver0");
> and what is the new method?
>

The “new” method is there since w2k. Read WDK docs about device interfaces. I’d bet KMDF makes most or even all necessary work for you but I’ve never examined this part. It is rather simple even for WDM driver. It is more complicated in user mode but there are advantages against the obsolete approach. You just enumerate devices for given interface identified by GUID and don’t need to try all possible numbers which your driver can assign to the device. If you just increment device number, how many device do you want to try in user mode? 100? 1000? Would it be sufficient if OS runs for years without rebooting?

As for the first part, Doron already answered. I’d only add it is basic C question and fluent C knowledge is prerequisite for any drivers writer.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]


From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of xxxxx@yahoo.com[SMTP:xxxxx@yahoo.com]
Reply To: Windows System Software Devs Interest List
Sent: Friday, January 25, 2008 2:32 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] WdfDeviceCreateSymbolicLink

I don’t know how to embed the variable into DECLARE_CONST_UNICODE_STRING(dosDeviceName, L"\DosDevices\Driver0");
and what is the new method?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer