• 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.

FSX XML/C++ Gauge problem

Messages
51
Country
france
Hello everyone.

I'm trying to make an example of a C++ gauge that manages XML variables.
I have the VS Express version so I can't debug my DLL... :(

My example is quite simple : an XML gauge displays the time since the launch of the gauge hh:mm:ss. I have 3 XML variables: TempsH, TempsM, TempsS.

The C++ gauge compiles and run fine but nothing happens.

Here's the gauge main file :

Code:
//	Set up gauge header
#pragma warning(disable : 4995)
#include <StrSafe.h>
#include "Temps.h"

//définition jauge
char manager_gauge_name[]		= GAUGE_NAME;
extern PELEMENT_HEADER		manager_list;
GAUGE_CALLBACK Update;

GAUGE_HEADER_FS700( 0, manager_gauge_name, &manager_list, \
						0, Update, 0, 0, 0 );

/////////////////////////////////////////////////////////////////////////////

MAKE_STATIC
(
	manager_background,
	0,
	0,
	0,
	IMAGE_USE_TRANSPARENCY,
	0,
	0, 0
)

PELEMENT_HEADER		manager_list	= &manager_background.header;

Temps tps = Temps();

void FSAPI Update ( PGAUGEHDR pgauge, SINT32 service_id, UINT32 extra_data )
{
	switch (service_id)
	{
		case PANEL_SERVICE_PRE_UPDATE:
		{
			tps.SetTemps();

			SINT32 heure=tps.getHeure();
			execute_calculator_code("(L:TempsH, enum)", 0, &heure, 0);

			SINT32 minute=tps.getMinute();
			execute_calculator_code("(L:TempsM, enum)", 0, &minute, 0);

			SINT32 seconde=tps.getSeconde();
			execute_calculator_code("(L:TempsS, enum)", 0, &seconde, 0);
		}
		break;
	}
}

/////////////////////////////////////////////////////////////////////////////
#undef GAUGE_NAME
#undef GAUGEHDR_VAR_NAME

This file uses the Temps Class :

header :

Code:
#include "..\inc\gauges.h"
#include <ctime>

using namespace std;

class Temps
{
private:
	SINT32 m_Depart;
	SINT32 m_Heure;
	SINT32 m_Minute;
	SINT32 m_Seconde;

public:
	Temps(void);
	~Temps(void);
	void SetTemps();
	SINT32 getHeure();
	SINT32 getMinute();
	SINT32 getSeconde();
};

cpp :

Code:
#include "Temps.h"


Temps::Temps(void)
{
	m_Depart=time(NULL);
}


Temps::~Temps(void)
{
}

void Temps::SetTemps()
{
	m_Heure=(time(NULL)/3600)-(m_Depart/3600);
	m_Minute=((time(NULL)/60)-(m_Depart/60))%60;
	m_Seconde=(time(NULL)-m_Depart)%60;
}

SINT32 Temps::getHeure()
{
	return m_Heure;
}

SINT32 Temps::getMinute()
{
	return m_Minute;
}

SINT32 Temps::getSeconde()
{
	return m_Seconde;
}

I can't see where's the error. Do you see anything chocking in these files ? :D

Thank you.
 
You can debug dlls in VS Express. Open FSX, select one of the default aircraft, then open your solution and select Attach To Process from the debug menu. Then switch to your aircraft that is using your dll and you are sorted. As for your code, execute_calculator_code can only output the value of a XML variable into a C variable. ie read only. Use the register_named_variable and check_named_variable and set_named_variable_value functions as described in the wiki.
 
You can debug dlls in VS Express. Open FSX, select one of the default aircraft, then open your solution and select Attach To Process from the debug menu.

Yep but it is not available for the Express version I think :

http://msdn.microsoft.com/fr-fr/library/c6wf8e4z

And I don't have such an option in my debug menu.

As for your code, execute_calculator_code can only output the value of a XML variable into a C variable. ie read only. Use the register_named_variable and check_named_variable and set_named_variable_value functions as described in the wiki.

Oh ok, that was a misunderstanding with taguilo. I thought I could use this function instead of set_named_variable_value() to modify my XML value. I will use these functions then.

Thank you :)
 
Odd....I use VS C++ 2008 Express and i have debug.

execute_calculator_code is the best option when it comes to reading from A vars or C:module: vars though.
 
Oh ok, that was a misunderstanding with taguilo. I thought I could use this function instead of set_named_variable_value() to modify my XML value. I will use these functions then.

You understood me quite well :), as you can perfectly use that function to modify XML var values.

What execute_calculator_code does it nothing more simple than to execute an XML script and save the result of the script into one of three pointers, depending on the type of data returned -INT,FLOAT or STRING

Going to your example, first I understand that code is only for testing purposes, as there would be unreasonable to write so much in C++ when a simple line in XML would give the same result.:D
Now, just staying with that example, you could write:

Code:
...
   case PANEL_SERVICE_PRE_UPDATE:
  {
       tps.SetTemps();
       char cTemp[200];
       SINT32 heure=tps.getHeure();
       SINT32 minute=tps.getMinute();
       SINT32 seconde=tps.getSeconde();
       sprintf_s(cTemp,"%d%s%d%s%d%s",heure," (>L:TempsH, enum) ",minute," (>L:TempsM, enum) ",seconde," (>L:TempsH, enum)");
       PCSTRINGZ szSetValue = cTemp;
       execute_calculator_code(szSetValue,NULL,NULL,NULL);
     }

Obviously there are multiple ways to code the example; I used this one just to show that this function doesn't limit only to retrieve XML values:D


Tom
 
To SEND a command with this method, use the following format:

Code:
execute_calculator_code("(>K:SOUND_TOGGLE)", NULL, NULL, NULL);

If you need to pass a value for a SET type key_event, simply use the same syntax used in an XML gauge by prefixing the command with the value (which can itself be another XML variable as shown below):

Code:
execute_calculator_code("(A:Plane heading degrees gyro,degrees) (>K:HEADING_BUG_SET)", NULL, NULL, NULL);

If you need to pass a value to a custom L:variable use the following format:

Code:
execute_calculator_code("myCvar_value (>L:MyXMLVar,unit)",NULL,NULL,NULL);
 
Bill, I found two inaccuracies on the wiki:

1) execute_calculator_code doesn't support Customvars (C:module:vars) handling within C gauges (.gau or .dll); instead they must be managed through local instances of IGaugeCCallback.

2) It doesn't support local C var names as part of the script; a container string must be used to pass their values:

FLOAT64 myVar = 100.00;
char cTemp[60];
sprintf_s(cTemp, %f%s, myVar, " (>L:MyVar,number)");
PCSTRINGZ szString = cTemp;
execute_calculator_code(szString,NULL,NULL,NULL);

Tom
 
Thanks, Tom. I've edited the Wiki entry and changed the string example to use (A:ATC_ID,string), and used your example in whole for the last format.
 
Thank you all. It's working and I'm glad it's in the wiki so other newbies will benefit from it ! :)
 
Last edited:
Back
Top