以下是我自己写的:
WAVEFORMATEX WaveFormatEx;
    LPDIRECTSOUNDBUFFER pBuffer=NULL;
LPDIRECTSOUNDBUFFER pBuffer2=NULL;
LPDIRECTSOUND pDS;
DSBUFFERDESC desc; HRESULT hr;
hr=DirectSoundCreate(NULL,&pDS,NULL);
if(hr!=DS_OK)
{
return FALSE;
}
    hr=pDS->SetCooperativeLevel(hWnd,DSSCL_PRIORITY);
memset(&desc,0,sizeof(DSBUFFERDESC));
desc.dwSize=sizeof(DSBUFFERDESC);
desc.dwFlags=DSBCAPS_PRIMARYBUFFER;
desc.dwBufferBytes=0;
desc.lpwfxFormat=NULL;
hr=pDS->CreateSoundBuffer(&desc,&pBuffer,NULL);
if(hr!=DS_OK)
{
return FALSE;
}
memset(&WaveFormatEx2,0,sizeof(WAVEFORMATEX));
WaveFormatEx2.cbSize=0;
WaveFormatEx2.nBlockAlign=16;
WaveFormatEx2.nChannels=2;
WaveFormatEx2.nSamplesPerSec=44100;
WaveFormatEx2.wBitsPerSample=16;
WaveFormatEx2.wFormatTag=WAVE_FORMAT_PCM;
WaveFormatEx2.nAvgBytesPerSec=WaveFormatEx2.nBlockAlign * WaveFormatEx.nSamplesPerSec;
pBuffer->SetFormat(&WaveFormatEx2);
memset(&desc,0,sizeof(DSBUFFERDESC));
desc.dwSize=sizeof(DSBUFFERDESC);
desc.dwFlags=DSBCAPS_STATIC|DSBCAPS_GLOBALFOCUS;
desc.dwBufferBytes=3 * WaveFormatEx.nAvgBytesPerSec;
desc.lpwfxFormat=&WaveFormatEx2;
hr=pDS->CreateSoundBuffer(&desc,&pBuffer2,NULL);
if(hr!=DS_OK)
{
AfxMessageBox("Error");
}
请问各位高手以上的有什么错呢?为何创建不了次缓冲区,总是执行AfxMessageBox("Error")这一句呢