Microsoft虚拟音频设备驱动程序示例(MSVAD)仅创建44个字节的文件

时间:2014-08-25 11:32:25

标签: c++ windows wdk

我目前正在深入研究MSVAD简单驱动程序。不幸的是,它并没有像我希望的那样工作。当一个新程序启动时,它在C:\

下创建为STREAM_NN.WAV

不幸的是,这个文件的大小只有44个字节(只包含标题)。我附加了调试器视图并得到了这个输出:

MSVAD: [CMiniportWaveCyclic::NewStream]
MSVAD: [CMiniportWaveCyclicMSVAD::ValidateFormat]
MSVAD: [CMiniportWaveCyclic::NewStream]
MSVAD: [CMiniportWaveCyclicMSVAD::ValidateFormat]
MSVAD: CMiniportWaveCyclicMSVAD::ValidatePcm
MSVAD: [CSaveData::InitializeWorkItems]
MSVAD: [CMiniportWaveCyclicStreamMSVAD::Init]
MSVAD: SaveData 845A754C
MSVAD: [CSaveData::SetDataFormat]
MSVAD: [CSaveData::Initialize]
MSVAD: [CMiniportWaveCyclicStreamMSVAD::AllocateBuffer]
MSVAD: [CMiniportWaveCyclicStreamMSVAD::SetFormat]
MSVAD: [CSaveData::SetDataFormat]
MSVAD: New Format: 44100
MSVAD: [CMiniportWaveCyclicStreamMSVAD::SetNotificationFreq]
MSVAD: [CMiniportWaveCyclicStreamMSVAD::SetState]
MSVAD: [CMiniportWaveCyclicStreamMSVAD::SetState]
MSVAD: KSSTATE_PAUSE
MSVAD: [CMiniportWaveCyclicStreamMSVAD::SetState]
MSVAD: KSSTATE_RUN
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=480]
MSVAD: [CSaveData::WriteData ulByteCount=1284]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=628]
MSVAD: [CSaveData::WriteData ulByteCount=1136]
//Truncated for convenience
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=776]
MSVAD: [CSaveData::WriteData ulByteCount=988]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CSaveData::WriteData ulByteCount=1764]
MSVAD: [CMiniportWaveCyclicStreamMSVAD::SetState]
MSVAD: KSSTATE_PAUSE
MSVAD: [CMiniportWaveCyclicStreamMSVAD::SetState]
MSVAD: KSSTATE_STOP
MSVAD: [CSaveData::WaitAllWorkItems]
MSVAD: [CSaveData::SaveFrame]
MSVAD: [CMiniportWaveCyclicStreamMSVAD::SetState]
MSVAD: [CMiniportWaveCyclicStream::~CMiniportWaveCyclicStream]
MSVAD: [CMiniportWaveCyclicStreamMS::~CMiniportWaveCyclicStreamMS]
MSVAD: [CMiniportWaveCyclicStreamMSVAD::FreeBuffer]
MSVAD: [CSaveData::~CSaveData]

这看起来很直接,例如调用所有必要的函数。我想知道这个例子中是否存在已知错误,或者我必须考虑的任何警告?

操作系统是虚拟机中的Windows 7 32位,正常的音频播放就像魅力一样。简单驱动程序设置为默认播放设备。

1 个答案:

答案 0 :(得分:4)

问题是,由于方法 CSaveData :: InitializeWorkItems(savedata.cpp)中的DDK 8添加了以下几行:

if (m_pWorkItems)
{
    return ntStatus;
}

但是 CSaveData :: ~CSaveData 只释放“工作项”,而不是m_pWorkItems数组。这导致将来使用释放的“工作项目”。

要解决此问题,您需要替换 savedata.cpp,CSaveData :: InitializeWorkItems 中的代码:

if (m_pWorkItems)
{
    return ntStatus;
}

m_pWorkItems = (PSAVEWORKER_PARAM)
    ExAllocatePoolWithTag
    (
        NonPagedPool,
        sizeof(SAVEWORKER_PARAM) * MAX_WORKER_ITEM_COUNT,
        MSVAD_POOLTAG
    );

通过此代码:

if (!m_pWorkItems)
{
    m_pWorkItems = (PSAVEWORKER_PARAM)
        ExAllocatePoolWithTag
        (
            NonPagedPool,
            sizeof(SAVEWORKER_PARAM) * MAX_WORKER_ITEM_COUNT,
            MSVAD_POOLTAG
        );
}