【求助】vs2012下DirectSound的问题
问题: if(FAILED(hr = mainbuffer->{
MessageBox(hWnd,TEXT("Create ....."),TEXT("Error"),MB_OK);
return 0;
}
总是创建失败,弹出对话框。 代码是照着某网站敲的。
顺便求解QueryInterface(IID_IDirectSound3DBuffer8,(LPVOID*)&sbuffer)是干什么用的?
代码如下:
//声音测试
LPDIRECTSOUNDBUFFER8 sbuffer = NULL;
LPDIRECTSOUND8 device = NULL;
CWaveFile* file = NULL;
HRESULT hr;
if(FAILED(hr = DirectSoundCreate8(NULL, &device, NULL)))
{
MessageBox(hWnd,TEXT("Create Sound"),TEXT("Error"),MB_OK);
return 0;
}
if(FAILED(hr = device->SetCooperativeLevel(hWnd, DSSCL_PRIORITY)))
{
MessageBox(hWnd,TEXT("Create Cooperative"),TEXT("Error"),MB_OK);
return 0;
}
file = new CWaveFile;
file->Open(_T("D:\\mySAO\\handsonic.wav"), NULL, WAVEFILE_READ);
DSBUFFERDESC desc;
ZeroMemory(&desc,sizeof(DSBUFFERDESC));
desc.dwSize = sizeof(DSBUFFERDESC);
desc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLFX| DSBCAPS_CTRLPOSITIONNOTIFY |DSBCAPS_GETCURRENTPOSITION2;
desc.dwBufferBytes = file->GetSize();
desc.lpwfxFormat = file->m_pwfx;
LPDIRECTSOUNDBUFFER mainbuffer = NULL;
if(FAILED(hr = device->CreateSoundBuffer(&desc,&mainbuffer,NULL)))
{
MessageBox(hWnd,TEXT("Create soubdbuffer"),TEXT("Error"),MB_OK);
return 0;
}
if(FAILED(hr = mainbuffer->QueryInterface(IID_IDirectSound3DBuffer8,(LPVOID*)&sbuffer)))
{
MessageBox(hWnd,TEXT("Create ....."),TEXT("Error"),MB_OK);
return 0;
}
mainbuffer->Release();
LPVOID lock;
DWORD len;
DWORD write;
sbuffer->Lock(0, 0, &lock, &len, NULL, NULL, DSBLOCK_ENTIREBUFFER);
file->Read((BYTE*)lock, len, &write);
sbuffer->Unlock((LPVOID)lock, len, NULL, 0);
sbuffer->SetCurrentPosition(0);