Let's say your device supports two interfaces and you want to expose both of them on the same device object. Furthermore, let's say that the I/O interface to each device interface is different. For instance, let's say that one interface allows only one create (e.g. it is exlusive) while the other allows unlimited handles opened against it. How can you enforce such a policy in your create dispatch routine?

Well this is what the ReferenceString parameter is for in the call to IoRegisterDeviceInterface (or WdfDeviceCreateDeviceInterface in KMDF). It allows you to distinguish between the two interface. In the create dispatch routine, the reference string will be passed to your driver in the FileName field of the PFILE_OBJECT. So all you have to do is a string compare and you are done... but there is a catch! There will be a '\' as the first character and then the remaining string, so you must account for the '\' as well. Let's see how you specify the reference string in your registration call and then check for it in your create dispatch routine.

#define EXCLUSIVE_STR L"Exclusive"

NTSTATUS DeviceInit(WDFDEVICE Device)
{

    UNICODE_STRING refExclusive;

    RtlInitUnicodeString(&refExclusive, EXCLUSIVE_STR);

    WdfDeviceCreateDeviceInterface(device, &GUID_DEVINTERFACE_EXCLUSIVE, &refExclusive);
    WdfDeviceCreateDeviceInterface(device, &GUID_DEVINTERFACE_NON_EXCLUSIVE, NULL);

    [...]
}

VOID EvtDeviceFileCreate(WDFDEVICE Device, WDFREQUEST Request, WDFFILEOBJECT FileObject)
{
    PCUNICODE_STRING pName;
    UNICODE_STRING refExclusive;

    RtlInitUnicodeString(&refExclusive, L"\\" EXCLUSIVE_STR);

    pName = WdfFileObjectGetFileName(WdfRequestGetFileObject(Request));

    if (RtlCompareUnicodeString(pName, &refExclusive, TRUE) == 0x0) {
        // opening GUID_DEVINTERFACE_EXCLUSIVE, verify exclusive access...
    }
    else {
        // opening GUID_DEVINTERFACE_NON_EXCLUSIVE...
    }

    [...]
}
But there is a problem! How you can tell if the application meant to open GUID_DEVINTERFACE_EXCLUSIVE, but left off the reference string and opened GUID_DEVINTERFACE_NON_EXCLUSIVE instead? You can fix this by using a reference string for both device interfaces and fail creates if either the wrong or no reference string is given.
#define EXCLUSIVE_STR L"Exclusive"
#define NON_EXCLUSIVE_STR L"NonExclusive"

NTSTATUS DeviceInit(WDFDEVICE Device)
{

    UNICODE_STRING refExclusive, refNonExclusive;

    RtlInitUnicodeString(&refExclusive, EXCLUSIVE_STR);
    RtlInitUnicodeString(&refNonExclusive, NON_EXCLUSIVE_STR);

    WdfDeviceCreateDeviceInterface(device, &GUID_DEVINTERFACE_EXCLUSIVE, &refExclusive);
    WdfDeviceCreateDeviceInterface(device, &GUID_DEVINTERFACE_NON_EXCLUSIVE, &refNonExclusive);

    [...]
}

VOID EvtDeviceFileCreate(WDFDEVICE Device, WDFREQUEST Request, WDFFILEOBJECT FileObject)
{
    PCUNICODE_STRING pName;
    UNICODE_STRING refExclusive, refNonExclusive;

    RtlInitUnicodeString(&refExclusive, L"\\" EXCLUSIVE_STR);
    RtlInitUnicodeString(&refNonExclusive, L"\\" NON_EXCLUSIVE_STR);

    pName = WdfFileObjectGetFileName(WdfRequestGetFileObject(Request));

    if (RtlCompareUnicodeString(pName, &refExclusive, TRUE) == 0x0) {
        // opening GUID_DEVINTERFACE_EXCLUSIVE, verify exclusive access...
    }
    else if (RtlCompareUnicodeString(pName, &refNonExclusive, TRUE) == 0x0) {
        // opening GUID_DEVINTERFACE_NON_EXCLUSIVE...
    }
    else {
        // fail the create, bad reference string
    }

    [...]
}