Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

GPS WP STRING

Featured Replies

  • Commercial Member

As you've probably guessed; I'm having lots of fun with the FS9/FSX GPS system. Most of it I think I've gotten to make sensible return values now but for some reason returning the waypoint ID is still eluding me. Getting it from gps_info.h is no problem but as WarpD kindly pointed out, the struct initialisation is unreliable. I know I'm doing something stupid here because the compiler is complaining violently about &wpt_name but after two hours of trying, I can't see the wood for the trees anymore.

char* GPSWptName(char data[]){	char wpt_name[6];	execute_calculator_code("(A:GPS WP STRING,Pointer)",NULL,NULL,&wpt_name);		strncpy(data,wpt_name,sizeof(wpt_name));	wpt_name[sizeof(wpt_name)]='\0';	return data;}

Can someone help please?-Dai

  • Author
  • Commercial Member

Aaaarghh!!! It really, really helps if I read what I write..... in the sd2gau series I say:'Note that for a string you must declare the variable as a PCSTRINGZ; the normal string or char will not work'So:-

char* GPSWptName(char data[]){	PCSTRINGZ wpt_name;	execute_calculator_code("(A:GPS WP STRING,Pointer)",NULL,NULL,&wpt_name);		strncpy(data,wpt_name,sizeof(wpt_name));	return data;}

works very nicely, thank you. Or at least it compiles. Just thought I'd leave this here as a perfect example of RTFM. Pwned!!!!-Dai

  • Moderator

Yep. I've had that bite me a number of times myself; forgetting precisely what I've warned others about... :(

Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator
  • Commercial Member

A few things:1 - wpt_name is a char array, not a pointer nor a PCSTRINGZ.2 - You're trying to pass the address to a char array, not a PCSTRINGZ. The function wants a pointer to a PCSTRINGZ pointer.3 - You're setting yourself up for possible buffer overrun with your strncpy because you're copying based on wpt_name's size which is a max of 6 and strncpy has no idea of the actual buffer size for data[].4 - You're far better off doing the entire thing something like this (not compile tested!):

PVOID GPSWptName(){  PCSTRINGZ p = NULL;  execute_calculator_code("(A:GPS WP STRING,Pointer)",NULL,NULL,&p);  return (PVOID)p;}

It is important that you pass the actual pointer back, and then do the copy where it's contents is actually used. The primary reason... clean, clear, visible control and accountability of memory pointers. :(

Ed Wilson

Mindstar Aviation
My Playland - I69

  • Author
  • Commercial Member

Thanks Ed. Being completely self-taught in programming C I'm very inclined to stupid blunders at times and there are many things I quite simply don't understand. If we're passing p back as a pointer, does the standard strncpy(local variable, p, size) still apply? It looks like it should do as I'm asking the pointer to show me its contents but the bit of information that I'm missing is how to call a PVOID function so that it gives me a return. I'm used to thedatatype variable=functionname(datatype variablename)method of calling.-Dai

  • Commercial Member

Ok... first... WHY use strncpy?? I see no advantage to using it myself. It offers no real protection nor efficiency. It's primary use is to copy a portion of a longer string.Here's an example of how to use what I wrote:char* wp_str = NULL;wp_str = (char*)GPSWptString();char my_wpt_str[41];strcpy_s(my_wpt_str,41,wp_str);The strcpy_s is a buffer overrun protected copy function. You could take it one step further and do it this way:strncpy_s(my_wpt_str,41,wpt_str,41);It won't copy past 41 characters, no matter what. If the GPS WP STRING is actually less than 41 chars in length, it will stop at the actual length of GPS WP STRING.

Ed Wilson

Mindstar Aviation
My Playland - I69

  • Author
  • Commercial Member

Thank you Ed - that all does make sense. I really should start using the new high security versions of old favourites - I have tended to use the sizeof() operator with strncpy to copy just the size of the required string but that has bitten me on a couple of occasions. I guess it's sheer blind luck that I've only ever caused one buffer overrun in FS and in that case it was fortunate that I knew instantly which buffer was too small. -Dai

  • Author
  • Commercial Member

Okay.... with Bill's help we finally figured that GPS WP STRING as listed in the gauges.h (fsxgauges_sp2.h) file does not work but GPS WP NEXT ID as listed in the XML variables does. Just thought it would be useful information.-Dai

  • Moderator
Okay.... with Bill's help we finally figured that GPS WP STRING as listed in the gauges.h (fsxgauges_sp2.h) file does not work but GPS WP NEXT ID as listed in the XML variables does. Just thought it would be useful information.-Dai
When looking for an XML token variable, gauges.h (anybody's version) is not the best place to look... :( Many of the C tokens have no XML equivalent, and vice versa. The token that works is curiously listed in a separate section of the XML variables list, which is why it took me several days to find it! :(

Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator
  • Moderator
Oops! Slip of the keyboard - I said gauges.h (etc) but to be absolutely clear, what I meant was the 'token variables' section of the SDK documentation. Now Bill's gonna tell me it's exactly the same thing.... :( -Dai
Well, it pretty much is. GPS_WP_STRING is actually a valid C token variable, but there is no direct equivalent in the list of XML variables. Further, it would appear that it actually doesn't work at all, as you have discovered... :(

Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator
  • Moderator
Looks like I've found two more that don't work either... GPS GROUND TRK and GPS GROUND HEADING. Where did you find GPS NEXT WPT ID, Bill? I'm being lazy here in asking... :( -Dai
(A:GPS GROUND TRUE TRACK,degrees)(A:GPS GROUND MAGNETIC TRACK,degrees)(A:GPS GROUND TRUE HEADING,degrees)In both cases you can request the return to be in radians if you prefer.Dai, either use the FS9 SDK's list of XML tokens in the parameters.doc file or the FSX SDK's list of XML tokens found in the Simulation Variables.html file cleverly hidden in the SDK's ...\SDK\Core Utilities Kit\Variables folder.Among the more "fun tokens" is this one:GPS APPROACH WP TYPEWaypoint type within approach mode (enum:0=None1=Fix2=Procedure turn left3=Procedure turn right4=Dme arc left5=Dme arc right6=Holding left7=Holding right8=Distance9=Altitude10=Manual sequence11= Vectors to final)

Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator
  • Author
  • Commercial Member
either use the FS9 SDK's list of XML tokens in the parameters.doc file or the FSX SDK's list of XML tokens found in the Simulation Variables.html file cleverly hidden in the SDK's ...\SDK\Core Utilities Kit\Variables folder.
<Dai wonders if it really is possible to reach round and kick one's own behind....>

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.