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

DLL instance handle

Messages
158
Country
us-northcarolina
Hi folks,

I've got a need to know the folder my current airplane lives in. As usual, FSDeveloper had the answer, a block of code posted by the ever-helpful Bill Leaming (where would we be without him?)

But -- there's a variable in there that I need called dll_instance. I presume this is the HINSTANCE of the gauge DLL. Where do I get that? I've poked about in the gauges.h and with google, to no avail so far.

Thanks!
Dutch


Code:
#include	"fs9gauges.h"
#include        <io.h>
#include	<stdio.h>

#define	MAX_SECTIONS	512
EXTERN_C	BOOL FindAircraft();

BOOL FindAircraft()
{
	char aircraftpath[MAX_PATH+1] = "",
	 searchpath[MAX_PATH+1]       = "",
	 cfgname[MAX_PATH+1]	      =	"",
 	 *helper   		      =	NULL;
	BOOL result		      =	FALSE;

  // dll_instance is the hInstance value of the DLL.
	GetModuleFileNameA(dll_instance,aircraftpath,MAX_PATH);
  // have the path to this gauge... delete the gauge name and the "\Panel" from it.
	if((helper=strrchr(aircraftpath,'\\'))!=NULL)
		*helper='\0';
	if((helper=strrchr(aircraftpath,'\\'))!=NULL)
		*helper='\0';
  // now, add '\aircraft.cfg' to it.
	strcat(aircraftpath,"\\aircraft.cfg");
  // it's all set for use.
  // do your .ini reads here

  //
  result = TRUE;

	return	result;
}
 
Dutch,

Note at the top of the code that I #include fs9gauges.h and not the default SDK gauges.h file...

This is a modified version of the stock gauges.h file with changes and additions made by the legendary duo Arne Bartells and Dai Griffiths over the years... :D

There are tons of very useful macros, functions(); and conversions included.

Search at Flightsim.com for the latest compilation of Dai's famous book which includes the modified gauges.h file:

http://www.flightsim.com/kdl.php?fid=133222

Code:
//-------------------------------------------------------------------------------
// GAUGE_TABLE_BEGIN
// GAUGE_TABLE_ENTRY
// GAUGE_TABLE_END
//
//	These macros build up the export table for the module by inserting gauge names
//	into the list of gauges
//-------------------------------------------------------------------------------

HINSTANCE dll_instance;  // This is added to allow each gauge's instance to be exposed

/* USAGE: Bitmap myStatic(dll_instance,L"STATIC_BMP"); in the gauge to load the resource! */

#define	GAUGE_TABLE_BEGIN()										\
		extern	GAUGEHDR	gauge_header;						\
		void FSAPI	module_init(void){}							\
		void FSAPI	module_deinit(void){}						\
		BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)	\
		{														\
			dll_instance = hDLL; return TRUE;					\
		}														\
																\
																\
		/* This is the module's import table.	*/				\
		GAUGESIMPORT	ImportTable =							\
		{														\
			{ 0x0000000F, (PPANELS)NULL },						\
			{ 0x00000000, NULL }								\
		};														\
																\
																\
		/* This is the module's export table.	*/				\
		GAUGESLINKAGE	Linkage =								\
		{														\
			0x00000013,											\
			module_init,										\
			module_deinit,										\
			0,													\
			0,													\
			FS9LINK_VERSION, {

#define GAUGE_TABLE_ENTRY(pgauge_header)		(pgauge_header),

#define	GAUGE_TABLE_END()						0 }};
 
Alas...this does no good if the gauge in question is stored in the Gauges folder!

Which mine is, and since my product is not aircraft-specific storing it in an aircraft's folder is not an option; it would be an installation and maintenance nightmare to attempt it.

Since 99.8 percent of my users will have FSUIPC and/or SimConnect, I will have to go that route ... unless there's another rabbit to be pulled out of a hat somehow.

Sigh,
Dutch
 
Ah, yes... The code is useless if the gauge is not in the a/c's ..\panel folder.

One way might be to pass the path via the 5th parameter, and have the user enter it as part of the gauge entry in the panel.cfg file.
 
The FSUIPC/SimConnect route works pretty well. I can't do anything that requires any configuration...the design goal is to work with any user aircraft without any changes to that aircraft whatsoever.

I'm lucky in that what I need this folder name for isn't a vital function of the system, more like a nice feature to have. If they want it and they're still running FS9 with no FSUIPC, they've got a decision to make.

I'd be worried if I thought a significant part of the potential customer base was FS9 and FSUIPC-less, but I doubt it. My potentials are mostly power flyers. Still, I'd love to be able to do without using the interface(s).

Dutch
 
Dutch, if you want to store something in a more "universal" manner, you might consider doing what I do...

...put the data in a custom folder within the User's App Data folder... :D

Then it won't matter if they have FSUIPC or SimConnect at all.
Code:
/*
  We want to ask Windows for the correct path to the Application Data folder.
  There are two versions of the folder, one is for each user the other is for all users.
	All users: CSIDL_APPDATA
	Current user: CSIDL_LOCAL_APPDATA
*/
	SHGetFolderPath(NULL,CSIDL_LOCAL_APPDATA,NULL,0,(LPSTR)&appdataPath);
 
Last edited:
A clever solution, Bill! :D

But for my purposes, I need to know the exact name of the folder the user's aircraft is stored in. I don't care about the path, I need the name of that folder.

Why? This is probably way more info than you asked for, but it may do me good to try and explain myself -- such a thing concentrates the mind wonderfully sometimes.

My product (FSCaptain) is a career simulator and flight environment that simulates an airline dispatcher's functions and contains elaborate code to automatically load fuel and payload into the user's aircraft. It has to be able to work with any user aircraft, and with, ideally, no tweaking at all by the user. To do its work accurately it needs more performance data and load data than is available from sim variables or in the aircraft.cfg.

So I have "extra-data" configuration files that supply the extra info, on a per-airplane-type basis. I key on the "atc_model" parameter in the aircraft.cfg to point to my "extra" data. This works for the performance data -- a B734 is a B734 -- but it doesn't handle the problem that there are many different simulations out there of a 737-400 with different payload station definitions and even fuel tank configurations!

So how to be able to store these different load chart configurations on a per-implementation basis without the user having to tweak anything to fly his favorite airplane? I lost lots of hair trying to solve this problem.

The only logical answer is: distribute the "extra data" load charts for the different simulations of a particular plane as files named for the folder the airplane is distributed with in my database.

Then when the user goes to fly his POSKY 737-400, FSCaptain looks for a load chart override file in its own database that matches the folder name the POSKY 737-400 lives in. That distinguishes it from the default 737-400 that comes with FS9 and any other 737-400 the user may have. It's the only unique identifier for different simulations I can think of.

So that's why I need the exact folder name of potentially any aircraft in the user's fleet...if there was any unique, consistent identifying data in the aircraft.cfg I could use I'd use it rather than the folder name...but I can't find any. Yes the title is unique and as consistent as the folder names, but it is unique on a per-paint basis not a per-airplane basis. I can't maintain and distribute a characteristics file for every repaint out there. It's nightmare enough to try and do it for every implementation of which there are many hundreds.

This job is a lot of fun!
Dutch
 
Thanks for the explanation. I understand now why knowing the a/c folder name is so critical...

I wish I had another rabbit in my hat!
 
Back
Top