//////////////////////////////////////////////////////////////////////////////// // DirectSoundBones.cpp // // DirectSound - loading a WAVE format resource #include #include #include #include #include "DSUtil.h" #include "resource.h" IDirectSound *pDS; BOOL InitDirectSound() { HRESULT h; h = DirectSoundCreate(NULL, &pDS, NULL); if (h != DS_OK) return FALSE; HWND hWnd = GetForegroundWindow(); if (hWnd == NULL) hWnd = GetDesktopWindow(); h = pDS->SetCooperativeLevel(hWnd, DSSCL_PRIORITY); if (h != DS_OK) { pDS->Release(); pDS = NULL; return FALSE; } IDirectSoundBuffer *lpDsb; DSBUFFERDESC dsbdesc; memset(&dsbdesc, 0, sizeof(DSBUFFERDESC)); dsbdesc.dwSize = sizeof(DSBUFFERDESC); dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER; dsbdesc.dwBufferBytes = 0; dsbdesc.lpwfxFormat = NULL; if (pDS->CreateSoundBuffer(&dsbdesc, &lpDsb, NULL) != DS_OK) { pDS->Release(); pDS = NULL; return FALSE; } lpDsb->Play(0, 0, DSBPLAY_LOOPING); return TRUE; } void ExitDirectSound() { if (pDS) { pDS->Release(); pDS = NULL; } } int _tmain() { DWORD dwStatus; if (!InitDirectSound()) return 1; IDirectSoundBuffer *pSound; pSound = DSLoadSoundBuffer(pDS, MAKEINTRESOURCE(IDR_SOUND)); if (pSound == NULL) return 2; printf("Playing sound...\n"); pSound->Play(0, 0, 0); do { Sleep(0); pSound->GetStatus(&dwStatus); } while (dwStatus & DSBSTATUS_PLAYING); return 0; }