dsound问题
下面段函数从SDK文档中获得,我想调用他来录音 但是有问题g_pDSBCapture还是等于0,请高人帮我看看
HRESULT CreateCaptureBuffer(LPDIRECTSOUNDCAPTURE8 pDSC,LPDIRECTSOUNDCAPTUREBUFFER8* ppDSCB8)
{
HRESULT hr;
DSCBUFFERDESC dscbd;
LPDIRECTSOUNDCAPTUREBUFFER pDSCB;
WAVEFORMATEX wfx ={WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0};
// wFormatTag, nChannels, nSamplesPerSec, mAvgBytesPerSec,
// nBlockAlign, wBitsPerSample, cbSize
if ((NULL == pDSC) || (NULL == ppDSCB8)) return E_INVALIDARG;
dscbd.dwSize = sizeof(DSCBUFFERDESC);
dscbd.dwFlags = 0;
dscbd.dwBufferBytes = wfx.nAvgBytesPerSec;
dscbd.dwReserved = 0;
dscbd.lpwfxFormat = &wfx; //设置录音用的wave格式
dscbd.dwFXCount = 0;
dscbd.lpDSCFXDesc = NULL;
if (SUCCEEDED(hr = pDSC->CreateCaptureBuffer(&dscbd, &pDSCB, NULL)))
{
hr = pDSCB->QueryInterface(IID_IDirectSoundCaptureBuffer8, (LPVOID*)ppDSCB8);
pDSCB->Release();
}
return hr;
}
LPDIRECTSOUNDCAPTURE8 g_pDSCapture = NULL;//设备对象指针
LPDIRECTSOUNDCAPTUREBUFFER8 g_pDSBCapture = NULL;//缓冲区对象指针
CreateCaptureBuffer(g_pDSCapture,&g_pDSBCapture);
函数调用后g_pDSBCapture还是0,上面函数是执行成功的即执行下面语句
if (SUCCEEDED(hr = pDSC->CreateCaptureBuffer(&dscbd, &pDSCB, NULL)))
{
hr = pDSCB->QueryInterface(IID_IDirectSoundCaptureBuffer8, (LPVOID*)ppDSCB8);
pDSCB->Release();
}
[解决办法]
HRESULT CreateCaptureBuffer(LPDIRECTSOUNDCAPTURE8 pDSC,LPDIRECTSOUNDCAPTUREBUFFER8* ppDSCB8)
刚进这个函数 就发现ppDSCB8是有值的 而不是我传进去的NULL
那肯定是不为空的啊,ppDSCB8是二级指针的吗!
就是在hr = pDSCB->QueryInterface(IID_IDirectSoundCaptureBuffer8, (LPVOID*)ppDSCB8);
同理啊,用断点拦截下来,看hr的值是多少?然后再在DX SDK中去找!
如果这个问题你都处理不了,劝你别用DX开发什么东东了!