将audio数据从Virtual Audio Driver发送到用户模式应用程序

我目前的任务是将audio数据从虚拟audio驱动程序发送到用户模式应用程序。

首先,我需要从用户模式应用程序创build该虚拟audio驱动程序的实例…

请参阅下面的代码片段

//Generating the device info //That works SetupDiGetClassDevs( &KSCATEGORY_AUDIO, NULL, NULL, DIGCF_PRESENT|DIGCF_DEVICEINTERFACE ); //Enumerating device interface //That works SetupDiEnumDeviceInterfaces(dev_info, &DeviceInfoData, &KSCATEGORY_AUDIO, i, &did); //Getting the path to device (pdd) //That works bRes = SetupDiGetDeviceInterfaceDetail(dev_info, &did, pdd, required_size, NULL, NULL); //Handle to the device //That works HANDLE hHandle = CreateFile( pdd->DevicePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); //Passing the Handle //That fails //PData is the Out buffer where we get the driver sending value bool bRc = DeviceIoControl ( hHandle, (DWORD)IOCTL_SIOCTL_METHOD_OUT_DIRECT, NULL, 0, &PData, sizeof( PData), &bytesReturned, NULL ); 

你能指出原因吗?

对于上面的用户模式应用程序,我用来编写一段IOCTL代码如下:

 NTSTATUS IoCtlHandler(PDEVICE_OBJECT pDeviceObject, PIRP Irp) { PAGED_CODE(); UINT dwDataSize = 0; PBYTE pReturnData ; pReturnData = (PBYTE)"IOCTL - Direct In I/O From Kernel Welcome to the world of Portcl"; dwDataSize = sizeof("IOCTL - Direct In I/O From Kernel! Welcome to the world of Portcl"); //Point to a certain IRP location pIoStackIrp = IoGetCurrentIrpStackLocation(Irp); if(pIoStackIrp) { switch(pIoStackIrp->Parameters.DeviceIoControl.IoControlCode) { //that ioctl i pass inside the DeviceIoControl function case IOCTL_SIOCTL_METHOD_OUT_DIRECT: { pOutputBuffer = NULL; NtStatus = STATUS_UNSUCCESSFUL; if(Irp->MdlAddress) { pOutputBuffer = MmGetSystemAddressForMdlSafe(Irp- >MdlAddress, NormalPagePriority); } RtlCopyBytes(pOutputBuffer, pReturnData, dwDataSize); break; } } } Irp->IoStatus.Information = dwDataSize; Irp->IoStatus.Status = NtStatus; //After all complete the IRP structure //As it is a adapter driver we pass this information to handle by adapter itself NtStatus = PcDispatchIrp(pDeviceObject, Irp); return NtStatus; } 

你能指出我的错误吗?为了我的testing目的,我只是传递一个string(IOCTL – 直接从内核I / O从欢迎来到Portcl的世界)到输出缓冲区稍后,我将replaceaudio数据。 ..为什么deviceIoControl失败,虽然我得到的string,无论我通过驱动程序,但字节返回值始终作为一个随机值与bRes值始终为false …