• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Some C Syntax Help Needed...

n4gix

Resource contributor
Messages
11,674
Country
unitedstates
have an urgent need to update my sound module to allow for increased flexibility by the users.

I have been using a predefined path to the sim's ..\Sound folder such as the following:

(GaugePlaySound)("sound\\MySound\\SND1.wav","",0)

I already know how to use the "fifth parameter" of the gauge entry to include a relative path, such as the following:

Code:
gauge00=MySound!SoundModule, 0,0,1,1,SimObjects\\Airplanes\\MyAirplane\\panel\\sound
Code:
CHAR sound_Path[MAX_PATH] = "";
int params_read = 0;
 
case PANEL_SERVICE_POST_INSTALL:
  if (pgauge->parameters && params_read == 0)
  {
        if ( strlen(pgauge->parameters) > 0 )
       {
          strcpy(sound_Path,(PCHAR)(pgauge->parameters)); 
          params_read = 1;
       }
 
  else if ( strlen(pgauge->parameters) == 0 )
  {
     params_read = 1;
  }

What I don't know however is the correct syntax for concantenating the char variable sound_Path so that it will replace the characters highlighted in red:

(GaugePlaySound)("sound\\MySound\\SND1.wav","",0)

Could it possibly be as simple as this:

Code:
(GaugePlaySound)(strcat(soundPath,"\\SND1.wav"),"",0)
 
Last edited:
It should do. this works

Code:
char sound_Path[MAX_PATH] = "";

strcpy(sound_Path,"sound\\MySound");
strcat(sound_Path, "\\SND1.wav");
 
Assuming sound_Path contains the path to your aircraft's audio files:

Code:
void playAudio(char wavFilename[])
{
	char filestr[MAX_PATH+1];

	sprintf_s(filestr, MAX_PATH, "%s%s", sound_Path, wavFilename);

	(GaugePlaySound)((LPTSTR)&filestr, "", 0);
}
 
Well, this is annoying, but not a showstopper!

While updating my sound module to use the "5th parameter" in a gauge entry of the panel.cfg file, I ran into a problem using strcat to construct my GaugePlaySound, etc. calls...

...because the strcat operation changes the contents of the sound_Path char variable! Argh!

Well, my solution while not "pretty or elegant" does work, although it's obviously a case of using a chainsaw where a surgeon's scapel is called for. I simply reset the contents of sound_Path after each call to the sound gauge: :o

Code:
if ( xml_SND1 == 1 ) { (GaugePlaySound)(strcat(sound_Path,"\\Snd1.wav"),"",0) ; xml_SND1 = 0 ; strcpy(sound_Path,(PCHAR)(pgauge->parameters)); }
if ( xml_SND1 == 2 ) { (GaugePlaySound)(strcat(sound_Path,"\\SND1.wav"),SND1,1) ; xml_SND1 = 0 ; strcpy(sound_Path,(PCHAR)(pgauge->parameters)); }
if ( xml_SND1 == 3 ) { (GaugeStopSound)(SND1) ; xml_SND1 = 0 ; }

if ( xml_SND2 == 1 ) { (GaugePlaySound)(strcat(sound_Path,"\\SND2.wav"),"",0) ; xml_SND2 = 0 ; strcpy(sound_Path,(PCHAR)(pgauge->parameters)); }
if ( xml_SND2 == 2 ) { (GaugePlaySound)(strcat(sound_Path,"\\SND2.wav"),SND2,1) ; xml_SND2 = 0 ; strcpy(sound_Path,(PCHAR)(pgauge->parameters)); }
if ( xml_SND2 == 3 ) { (GaugeStopSound)(SND2) ; xml_SND2 = 0 ; }
 
Last edited:
Well, of course it changes it... you told it to!

The first variable you passed to strcat is the destination of the contatenated string result. While you took advantage of it returning the result as well... the result is still the same memory address as the destination string that you provided it.
 
Well, of course it changes it... you told it to!
Yes, it seems obvious in retrospect, but then I'm certainly no type of guru, and it has been well over four years since last even looking at C... :rotfl:

However, at the moment I'm rather pressed for time, so had to use the sledge hammer instead of the jewlers' hammer.

Ultimately I'd like to turn the whole mess into a set of function(); calls using a more refined technique.
 
create a temporary char array inside the function you are calling, use strcpy to copy sound_Path to that, then use strcat on the temporary char array?
 
Back
Top