|
Here you go... some code to get it going and to shut it down, it should be simple enough to convert to C++ if you want. What comes next is adding code to load in a WAVE file (or some other type of sound file), parse it's header, then create a sound buffer that DirectSound can actually play.
#include "dsound.h"
extern HWND hMainWnd; //handle to the window from the main windows program
static LPDIRECTSOUND lpDS; //pointer to the directsound object
/* This function will initialize Direct Sound */
/* it returns TRUE if it was successful or FALSE otherwise */
BOOL Sound_Init(void)
{
if (DS_OK==DirectSoundCreate(NULL,&lpDS,NULL)) //create direct sound object
{
//ok, DirectSound Object created, let's take control now...
if (DS_OK==IDirectSound_SetCooperativeLevel(lpDS, hMainWnd, DSSCL_EXCLUSIVE))
{
//MessageBox(hMainWnd,"Cooperative Level Succefully Set!","Good!!",MB_OK);
return TRUE;
}
else //SetCoop was unsuccessful, let's give up control
{
IDirectSound_Release(lpDS);
MessageBox(hMainWnd,"Set Cooperative Level didn't Work!","BAD!!",MB_OK);
return FALSE;
}
}
else //DSObj creation was unsuccessful
{
MessageBox(hMainWnd,"Could Not Create Direct Sound Object","Error!",MB_OK);
return (FALSE);
}
}
/*here's a simple function to shut down direct sound when you're done with it */
void Sound_Exit(void)
{
if (lpDS)
{
IDirectSound_Release(lpDS);
}
else
{
MessageBox(hMainWnd,"Sound was not initialized and cannot Exit!","Error!",MB_OK);
}
}
|
|