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... } [...] }
#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 } [...] }