i note strange bug - if open device with interface KSCATEGORY_VIDEO_CAMERA, close it and just FAST try re-open again - STATUS_CANCELLED. so
CreateFileW (name) // OK
NtClose()
CreateFileW (name) // STATUS_CANCELLED
CreateFileW (name) // again OK
but if set even micro delay, before second CreateFileW call ( say Sleep(1) ) - second open again ok. if step this part of code under debugger, will be no STATUS_CANCELLED again. if again try open file, after STATUS_CANCELLED,again all will be ok. i note this only on interface KSCATEGORY_VIDEO_CAMERA. no such problem on KSCATEGORY_AUDIO or any other devices. i note this bug and on latest win 11 25H2 and on very old win 8.1 - the same behavior. example for reproduce:
void test(_In_ PCWSTR pszDeviceInterface, ULONG n)
{
while (*pszDeviceInterface)
{
PWSTR name;
// i no show implementation of GetFriendlyName here, not related, can be skipped
if (!GetFriendlyName(&name, pszDeviceInterface))
{
DbgPrint("*********************************\r\n%ws \"%ws\"\r\n", pszDeviceInterface, name);
LocalFree(name);
}
ULONG m = n, i = 0;
BOOL bWasError = FALSE, bWasSleep = FALSE;
do
{
if (!bWasError)
{
if (++i & 1)
{
Sleep(1);
bWasSleep = TRUE;
}
}
if (HANDLE hFile = fixH(CreateFileW(pszDeviceInterface, 0, 0, 0, OPEN_EXISTING, 0, 0)))
{
NtClose(hFile);
bWasError = FALSE;
}
else
{
bWasError = TRUE;
DbgPrint("\t%x) %x [%x]\r\n", m - n, RtlGetLastNtStatus(), bWasSleep);
}
bWasSleep = FALSE;
} while (--n);
n = m;
pszDeviceInterface += wcslen(pszDeviceInterface) + 1;
}
}
CONFIGRET test(_In_ const GUID* InterfaceClassGuid, ULONG n = 8)
{
CONFIGRET cr;
do
{
ULONG ulLen;
if (cr = CM_Get_Device_Interface_List_SizeW(&ulLen,
const_cast<GUID*>(InterfaceClassGuid), 0, CM_GET_DEVICE_INTERFACE_LIST_PRESENT))
{
return cr;
}
if (ulLen <= 1)
{
return CR_NO_SUCH_DEVNODE;
}
cr = CR_OUT_OF_MEMORY;
if (PZZWSTR Buffer = (PZZWSTR)LocalAlloc(0, ulLen * sizeof(WCHAR)))
{
if (!(cr = CM_Get_Device_Interface_ListW(const_cast<GUID*>(InterfaceClassGuid),
0, Buffer, ulLen, CM_GET_DEVICE_INTERFACE_LIST_PRESENT)))
{
test(Buffer, n);
}
LocalFree(Buffer);
}
} while (cr == CR_BUFFER_SMALL);
return cr;
}
inline HANDLE fixH(HANDLE hFile)
{
return hFile == INVALID_HANDLE_VALUE ? 0 : hFile;
}
test(&KSCATEGORY_VIDEO_CAMERA);
test(&KSCATEGORY_CAPTURE);
test(&KSCATEGORY_AUDIO);
test(&GUID_DEVINTERFACE_VOLUME);
so for compare KSCATEGORY_VIDEO_CAMERA and KSCATEGORY_AUDIO:
usbccgp - usbvideo - ksthunk // was STATUS_CANCELLED on fast reopen
usbccgp - usbaudio - ksthunk // always ok
so can assume that problem in usbvideo.sys but not found exactly where and why
question:
- are this known issue ?
- why this happens ?
- how fix ? simply try reopen file again after STATUS_CANCELLED ? this work but not nice
typical output:
win 11 25h2
*********************************
\\?\USB#VID_046D&PID_0825&MI_00#6&167c7536&0&0000#{e5323777-f976-4f5b-9b55-b94699c46e44}\GLOBAL "Logi C270 HD WebCam"
1) c0000120 [0]
4) c0000120 [0]
7) c0000120 [0]
*********************************
\\?\USB#VID_046D&PID_0825&MI_00#6&167c7536&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\GLOBAL "Logi C270 HD WebCam"
1) c0000120 [0]
4) c0000120 [0]
7) c0000120 [0]
*********************************
\\?\USB#VID_046D&PID_0825&MI_02#6&167c7536&0&0002#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\GLOBAL "Logi C270 HD WebCam"
*********************************
\\?\HDAUDIO#FUNC_01&VEN_8086&DEV_280B&SUBSYS_80860101&REV_1000#4&2b2eca69&0&0201#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\intcdaudlegacytopo_8_192_24_d0 "Intel(R) Display Audio Mixer 1"
*********************************
\\?\HDAUDIO#FUNC_01&VEN_8086&DEV_280B&SUBSYS_80860101&REV_1000#4&2b2eca69&0&0201#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\intcdaudlegacywave_0 "Intel(R) Display Audio Output 1"
*********************************
\\?\HDAUDIO#FUNC_01&VEN_10EC&DEV_0887&SUBSYS_1462FA74&REV_1003#4&2b2eca69&0&0001#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\elineouttopo "HD Audio Speaker mixer"
*********************************
\\?\HDAUDIO#FUNC_01&VEN_10EC&DEV_0887&SUBSYS_1462FA74&REV_1003#4&2b2eca69&0&0001#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\emicintopo "HD Audio Microphone mixer"
*********************************
\\?\USB#VID_046D&PID_0825&MI_02#6&167c7536&0&0002#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\GLOBAL "Logi C270 HD WebCam"
*********************************
\\?\HDAUDIO#FUNC_01&VEN_10EC&DEV_0887&SUBSYS_1462FA74&REV_1003#4&2b2eca69&0&0001#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\eheadphonetopo "HD Audio Headphone mixer"
*********************************
\\?\HDAUDIO#FUNC_01&VEN_10EC&DEV_0887&SUBSYS_1462FA74&REV_1003#4&2b2eca69&0&0001#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\emixedcapturetopo "HD Audio Mixed capture mixer"
win 8.1
*********************************
\\?\USB#VID_5986&PID_0547&MI_00#7&15193841&0&0000#{e5323777-f976-4f5b-9b55-b94699c46e44}\GLOBAL "NEC HD WebCam"
1) c0000120 [0]
4) c0000120 [0]
7) c0000120 [0]
*********************************
\\?\HDAUDIO#FUNC_01&VEN_10EC&DEV_0892&SUBSYS_1462111B&REV_1003#4&236042ed&0&0001#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\eMicIn2Wave "HD Audio Microphone 2"
*********************************
\\?\USB#VID_5986&PID_0547&MI_00#7&15193841&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\GLOBAL "NEC HD WebCam"
1) c0000120 [0]
4) c0000120 [0]
7) c0000120 [0]
*********************************
\\?\HDAUDIO#FUNC_01&VEN_10EC&DEV_0892&SUBSYS_1462111B&REV_1003#4&236042ed&0&0001#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\eMicIn2Topo "HD Audio Microphone 2 mixer"
*********************************
\\?\HDAUDIO#FUNC_01&VEN_10EC&DEV_0892&SUBSYS_1462111B&REV_1003#4&236042ed&0&0001#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\eSpeakerTopo "HD Audio Speaker mixer"
*********************************
\\?\HDAUDIO#FUNC_01&VEN_10EC&DEV_0892&SUBSYS_1462111B&REV_1003#4&236042ed&0&0001#{6994ad04-93ef-11d0-a3cc-00a0c9223196}\eHeadphoneTopo "HD Audio Headphone mixer"