从虚拟音频驱动程序将音频数据发送到用户模式应用程序

发布于 2024-12-27 19:14:13 字数 2780 浏览 2 评论 0 原文

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

首先,我需要从用户模式应用程序创建该虚拟音频驱动程序的实例...

请参阅下面的代码片段,

//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;
}

请您指出我的错误。为了我的测试目的,我只是传递一个字符串(IOCTL - Direct In I/O From Kernel Welcome to Portcl 的世界”)到输出缓冲区稍后我将用音频数据替换它...为什么 deviceIoControl 失败,尽管我得到了在驱动程序中传递的字符串,但 bytesReturn 值始终作为随机值出现,而 bRes 值始终为 false ...

I have my current task to send audio data from virtual audio driver to user mode application.

First I need to create an instance of that virtual audio driver from an user mode application ...

Please see the code snippet below

//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 );

Could you please point out the reason?

For that above user mode application I used to write a piece of IOCTL code as follows...

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;
}

Could you please point out my mistake.For my testing purpose I am just passing a string (IOCTL - Direct In I/O From Kernel Welcome to the world of Portcl") to the output buffer later on I would replace it by audio data...Why deviceIoControl fails though I get the string whatever I passes in driver but the bytesReturn value always coming as a random value with bRes value always false...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文