根据Microsoft documentation: “您可以在将[pwfx]结构传递给waveOutOpen之后立即释放它。”
但是此代码似乎不同意:
pwfx=new WAVEFORMATEX;
pwfx->wFormatTag=WAVE_FORMAT_PCM;
pwfx->nChannels=2;
pwfx->nSamplesPerSec=SPS;
pwfx->nAvgBytesPerSec=SPS*2;
pwfx->nBlockAlign=2;
pwfx->wBitsPerSample=8;
mmres=waveOutOpen(&ghwo,uDeviceID,pwfx,dwCallback,dwCallbackInstance,fdwOpen);
delete pwfx;
答案 0 :(得分:2)
The only problem I can see in the code you provided is that you did not fully initialise the struct. You did not initialise cbSize
which in this instance must be set to 0
.
Given that you are not allocating any extra data at the end of this struct, there's no need to allocate it in the heap.
It's entirely plausible that the problem lies in the other parameters that you pass to the function. We can't see any details of them, and therefore can't comment.
答案 1 :(得分:1)
您不需要new
或delete
任何东西。您可以这样做:
WAVEFORMATEX wfx = { };
wfx.wFormatTag=WAVE_FORMAT_PCM;
...
mmres=waveOutOpen(&ghwo,uDeviceID,&wfx,dwCallback,dwCallbackInstance,fdwOpen);
这有帮助吗?