Home | Gaming | Programming | Play Online | Contact | Keyword Query
Games++ Games & Game Programming

Games++ Home
Games++ Gaming
Games++ Programming
Beta Testing Games
Free Online Games
Hints & Cheats

E-mail This Page
Add to Favorites


Web Games++

Cheat Codes
Trickster Wiki
Game Ratings
Gameboy Cheats
PlayStation Cheats
BlackBerry Games
Photoshop Tutorials
Illustrator Tutorials
ImageReady Tutorials


Setting Up DirectSound


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
         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)
      MessageBox(hMainWnd,"Sound was not initialized and cannot Exit!","Error!",MB_OK);
Copyright © 1998-2007, Games++ All rights reserved. | Privacy Policy