Hi Tim,
Yes, you are right, that is a mistake and I mean error code 2 ERROR_FILE_NOT_FOUND as you mention, thanks for you correction.
And here is the code pieces I use to get the file name and attempt to open it.
int FindAndOpenDevice(void)
{
GUID guid = { 0x96b4c8f2L, 0xeb14, 0x4a80, 0xa6, 0x11, 0x07, 0xfa, 0xc1, 0x07, 0x29, 0xa8 };
CONFIGRET cr;
PWSTR DeviceInterfaceList = NULL;
ULONG DeviceInterfaceListLength = 0;
cr = CM_Get_Device_Interface_List_Size(
&DeviceInterfaceListLength,
&guid,
NULL,
CM_GET_DEVICE_INTERFACE_LIST_ALL_DEVICES
);
if (cr != CR_SUCCESS) {
wprintf(L"fail to get interface list size\n");
return -1;
}
DeviceInterfaceList = (PWSTR)HeapAlloc(
GetProcessHeap(),
HEAP_ZERO_MEMORY,
DeviceInterfaceListLength * sizeof(WCHAR));
if (DeviceInterfaceList == NULL) {
wprintf(L"allocate interface list buffer fail\n");
return -2;
}
cr = CM_Get_Device_Interface_List(
&guid,
NULL,
DeviceInterfaceList,
DeviceInterfaceListLength,
CM_GET_DEVICE_INTERFACE_LIST_ALL_DEVICES);
if (cr != CR_SUCCESS) {
wprintf(L"fail to get interface list\n");
return -3;
}
wprintf(L"%s\n", DeviceInterfaceList);
HANDLE hDev = INVALID_HANDLE_VALUE;
hDev = CreateFile(
DeviceInterfaceList,
FILE_GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
0,
NULL
);
if (hDev == INVALID_HANDLE_VALUE) {
wprintf(L"fail to open device (0x%X)\n", GetLastError());
return -4;
}
CloseHandle(hDev);
}
Through above function, I will get the console output (compiled with Unicode character set)
\\?\ROOT#MEDIA#0001#{96b4c8f2-eb14-4a80-a611-07fac10729a8}
fail to open device (0x2)
I also try to execute the program as administrator, but it looks no difference.
Please advise me if there are anything need to check, thank you.