GaugeSound.dll

From FSDeveloper Wiki
Jump to: navigation, search

If you wish to use the GaugeSound.dll in your gauge(s), the first step is to declare the following in your main gauge (.cpp) file:

// Sound declarations
	typedef VOID (*TGaugePlaySound)(LPTSTR,LPSTR,int);
	typedef VOID (*TGaugeStopSound)(LPTSTR);
	typedef VOID (*TTerminateSounds)();
	TGaugePlaySound GaugePlaySound;
	TGaugeStopSound GaugeStopSound;
	TTerminateSounds TerminateSounds;
	HMODULE MGaugeSound;

	// If you need to "loop" some sounds, define the "stop loop string names"
	LPSTR flap = "flap";
	LPSTR gearhorn = "gearhorn";
	LPSTR overspeed = "overspeed";
	LPSTR firetest = "firetest";
	LPSTR geartest = "geartest";
	LPSTR speedtest = "speedtest";
	LPSTR warning = "warning";

Next, initialize the following in the PANEL_SERVICE_PRE_INITIALIZE case:

	case PANEL_SERVICE_PRE_INITIALIZE:
		if (MGaugeSound == NULL) {MGaugeSound = LoadLibrary("GaugeSound");}
		GaugePlaySound = (TGaugePlaySound)GetProcAddress(MGaugeSound,"GaugePlaySound");
		GaugeStopSound = (TGaugeStopSound)GetProcAddress(MGaugeSound,"GaugeStopSound");
		TerminateSounds = (TTerminateSounds)GetProcAddress(MGaugeSound,"TerminateSounds");
 	break;

Next, add the following to the PANEL_SERVICE_PRE_UPDATE case:

	case PANEL_SERVICE_PRE_UPDATE:
		MGaugeSound = GetModuleHandle("GaugeSound");
		if (MGaugeSound == NULL) {MGaugeSound = LoadLibrary("GaugeSound");}
		GaugePlaySound = (TGaugePlaySound)GetProcAddress(MGaugeSound,"GaugePlaySound");
		GaugeStopSound = (TGaugeStopSound)GetProcAddress(MGaugeSound,"GaugeStopSound");
		TerminateSounds = (TTerminateSounds)GetProcAddress(MGaugeSound,"TerminateSounds");
 	break;


Finally, add this to the PANEL_SERVICE_PRE_KILL case:

	case PANEL_SERVICE_PRE_KILL:
		MGaugeSound = GetModuleHandle("GaugeSound");
		if (MGaugeSound == NULL) {MGaugeSound = LoadLibrary("GaugeSound");}
		GaugePlaySound = (TGaugePlaySound)GetProcAddress(MGaugeSound,"GaugePlaySound");
		GaugeStopSound = (TGaugeStopSound)GetProcAddress(MGaugeSound,"GaugeStopSound");
		TerminateSounds = (TTerminateSounds)GetProcAddress(MGaugeSound,"TerminateSounds");
		(TerminateSounds)();
		FreeLibrary(MGaugeSound);
 	break;

To play a sound, use one of the following examples in a mouse callback. Note that "PathName" is the sub-folder name in the default FS ..\Sound folder, e.g., ..\Sound\Milviz. "SoundName" is for example push.wav:

Play once:

    (GaugePlaySound)("sound\\PathName\\SoundName.wav","",0) ; 

Loop Sound:

Looping a sound continuously require that you specify a "stop loop string name" and set the third parameter to 1 (0 = play once, 1 = loop continuously).

     if ( *rotartest == 2 ) 
          { (GaugePlaySound)("soundesdggearhorn.wav",geartest,1) ; } 
     else { (GaugeStopSound)(geartest); }