标题:【求助】vs2012下DirectSound的问题
取消只看楼主
lq983065876
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-6-13
结帖率:0
已结贴  问题点数:20 回复次数:0 
【求助】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);
         
搜索更多相关主题的帖子: Create return 对话框 干什么 
2013-06-13 23:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-415137-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.309946 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved