@Tim_Roberts said:
my device is already registered at 4d36e96c-e325-11ce-bfc1-08002be10318 in registry
That GUID does not belong to you. Thatâs a Microsoft GUID, and exposing it makes other promises. You need to create your own GUID for your own private interface.
All of the casts you are doing make me suspicious that youâve made a rookie mistake. You shouldnât have to cast any of that. Just for now, you should throw out the _tprintf
and use straight puts
to make absolutely sure youâre getting an ANSI string, and not a Unicode string. Get rid of any casts where you are passing that variable to other APIs. If you get compilation errors, then you are mixing character sets, which is disastrous. Thatâs especially true for CreateFile
. If you have to cast the file name to get it into CreateFile
, then you have made a mistake.
How to know who(user app or audio engine) calls IRP_MJ_CREATE
Itâs tricky, The most common way is to add a reference string when you create your device interface, and look for that reference string in the file name field when you get the IRP_MJ_CREATE call.
Is your create handler getting called at all? Iâm guessing it isnât, because you would have seen a blue screen. Does your device appear in Device Manager as a sound device?
Hi Tim,
You are right, i have seen bluescreen issue, but my device appear in device manager, and also i can see the virtual mic in my sound control panel, the only issue i am facing is blue screen(thats bcz of PCDispatcher as u mentioned in create function) and CreateFile error.
for CreateFile i removed all the casting:
GUID guid = {0x4d36e96c, 0xe325, 0x11ce, 0xbf, 0xc1, 0x8, 0x0, 0x2b, 0xe1, 0x3, 0x18 };
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,/////////////////////////////getting error here: 'function': incompatible types - from 'PWSTR' to 'PZZSTR'
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;
}
plz help me to resolve âfunctionâ: incompatible types - from âPWSTRâ to âPZZSTRâ error in CM_Get_Device_Interface_List function