Archived

This topic is now archived and is closed to further replies.

dragonflightdesign

Define Ini-Values for Local Variables in a INI- or CFG-File with XML

Recommended Posts

Hello again!i use only XML for my gauges. I try to make a gauge with moving map in VC. For this i need to define some bitmap values to show the map in the right way. I dont want to force simmers to edit xml- gauge files.Is there any possibility, to edit a ini-file or cfg-file and read it with xml?any idea?

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Hi AndiThe only way that this can be done is by writing a small C-gauge to read the ini file and then pass the data using SimConnect - see the Cabin Comfort example in the SDK.-Dai

Share this post


Link to post
Share on other sites

Hi Dai, just FYI, the Cabin Comfort does not use SimConnect, it's direct C++ code -but you can call SimConnect routines from a C++ module as well.Tom

Share this post


Link to post
Share on other sites

thank you for your replies,so i started thinking about old time fortran knowledge and installed visual C++. it's heavy, but time goes by and i think i will manage it.thank you!

Share this post


Link to post
Share on other sites

This should get you started... It's the code I used for just such a gauge.char dsd_xml_config_gauge_name[] = GAUGE_NAME;extern PELEMENT_HEADER dsd_xml_config_list;PELEMENT_STATIC_IMAGE bg_element = NULL;GAUGE_CALLBACK gaugecall;GAUGE_HEADER_FS700(GAUGE_W, dsd_xml_config_gauge_name, &dsd_xml_config_list, NULL, gaugecall, 0, 0, 0);typedef struct Xml_Data{ char name[130]; double value; ID xml_id;} Xml_Data;Xml_Data *float_value = NULL;char xml_base[30];char label_name[35];char xml_name[35];char ini_name[130];char lvar_in[130];char id_number[4];char target_string[30];PCHAR file_extension = ".ini0";int params_read = 0;int max_values = 0;int i = 0;void FSAPI gaugecall(PGAUGEHDR pgauge, int service_id, UINT32 extra_data){switch(service_id){case PANEL_SERVICE_PRE_UPDATE:if ( pgauge->parameters ){if ( params_read == 0 ){if ( strlen(pgauge->parameters) > 0 ) { strcpy_s( ini_name,130,(PCHAR)( pgauge->parameters ) ); params_read = 1; }else if ( strlen( pgauge->parameters ) == 0 ) { strcpy_s ( ini_name,130, "./Gauges/dsd_xml_config.ini0" ); params_read = 1; }max_values = GetPrivateProfileInt("Config", "MaxValues", 100, ini_name);if ( max_values > 100 || max_values < 1 ) { max_values = 100; }float_value = new Xml_Data[max_values+1];i = 0;while ( i < max_values ) { strcpy_s( xml_name,35,"LVar_" ); strcpy_s ( label_name,35,"Value_" ); if ( i < 10 ) strcat_s ( xml_name,35, "0" ); if ( i < 10 ) strcat_s ( label_name,35, "0" ); _itoa_s( i, id_number,4, 10 ); strcat_s ( xml_name,35, id_number ); strcat_s ( label_name,35, id_number ); GetPrivateProfileString( "Floats", label_name, "0", target_string, 32, ini_name ); GetPrivateProfileString( "LVars", xml_name, "", lvar_in, 128, ini_name ); float_value.value = atof( target_string ); if ( strlen(lvar_in) > 0 ) strcpy_s( float_value.name,130, lvar_in ); else { strcpy_s( float_value.name,130, "dsd_xml_" ); if ( i < 10 ) strcat_s ( float_value.name,130, "0" ); strcat_s ( float_value.name,130, id_number ); } float_value.xml_id = check_named_variable( float_value.name ); if ( float_value.xml_id == 0 ) float_value.xml_id = register_named_variable( float_value.name ); set_named_variable_value( float_value.xml_id, float_value.value ); i++; }}}break;case PANEL_SERVICE_PRE_INITIALIZE:i = 0;while ( i < max_values ){ float_value.xml_id = check_named_variable( float_value.name ); i++;}break;case PANEL_SERVICE_PRE_KILL:i = 0;while ( i < max_values ){ if (strcpy_s ( label_name,"Value_" )) {WritePrivateProfileString("Errors", "LVar", "Value", ini_name);} if ( i < 10 ) { if (strcat_s ( label_name, "0" )) {WritePrivateProfileString("Errors", "LVar", "ZeroPad", ini_name);} } if (_itoa_s( i, id_number, 10 )) {WritePrivateProfileString("Errors", "LVar", "Number", ini_name);} if (strcat_s ( label_name, id_number )) {WritePrivateProfileString("Errors", "LVar", "NameCreation", ini_name);} float_value.xml_id = check_named_variable( float_value.name ); float_value.value = get_named_variable_value( float_value.xml_id ); if (_gcvt_s(target_string, float_value.value, 15)) {WritePrivateProfileString("Errors", "LVar", "NumberCoversion", ini_name);} WritePrivateProfileString ("Floats", label_name, target_string, ini_name ); i++;}break;case PANEL_SERVICE_DISCONNECT: delete[] float_value;break;}}MAKE_STATIC(Static1,Rec0,NULL,NULL,IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY | BIT7,0,0,0)PELEMENT_HEADER dsd_xml_config_list = &Static1.header;Doug

Share this post


Link to post
Share on other sites

Thanks a lot for sharing this code!But I get compile errors, something about linkage errors or non solved linkages concerning some 610 macros.I'll need to check if errors aren't caused by the rest of the project, written by me (which is more probably...) Maybe I forgot some includes ?Herbert

Share this post


Link to post
Share on other sites

Hi HerbieFS610 refers to the FS98 macros which are no longer used in FS at all. I'd check your gauge headers somewhere; if you look at Doug's code he is calling FS700 (FS2000) which is the earliest version header still supported. I have removed them entirely from my fs9_gauges.h header file onwards; beats me why Microsoft left them there. So if you are trying to compile using any of my header files from fs9_gauges.h onwards then your code will fail.-Dai

Share this post


Link to post
Share on other sites