• 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 Data exchange between gauges, C++

OT but reminds me....I am still hoping for that SDK for reading active flightplan data from ya :cool:
 
I am not sure whether you can share pointers to structures/classes using FSX variables across different DLLs. I seriously doubt it due to ODR vialation, though never tried it ;) It could work if you use same compiler and your projects are configured identically, however CRT dependency on lcient machine could harm the solution. The safe way (not security, just feasibility, use of compiler, crt version, etc.) is to use vtable as in the example I have shown. If you want to share standard data types, then FSX variables are enough and best choice ...
you will find nice article about the techinique here:
http://www.codeproject.com/Articles/28969/HowTo-Export-C-classes-from-a-DLL
That's really weird, but I cannot get it working with FSX. The sim does not load the newly created gauge.
I found the callback function, e.g., the "void FSAPI GaugeMainCBF()" is not being called at all.
And the "Debug" Output tab in Visual Studio shows the following:
...
'fsx.exe': Loaded 'F:\FSX\SimObjects\Airplanes\BS\Panel\Gauge2.dll', No symbols loaded.
'fsx.exe': Unloaded 'F:\FSX\SimObjects\Airplanes\BS\Panel\Gauge2.dll'
...

But after I remove/disable the code given below, the problem disappears! Here is it:
Code:
   ...
   case PANEL_SERVICE_PRE_UPDATE:
  {
      IFadec* pFadec = ::GetFadec(); // COM-like accessing.
      if(pFadec)
      {
          pFadec->GetN1(42);
          pFadec->Release();
      }
   ...

No difference where is this code located: in the callback, in the module_init() or in DllMain() - if it's present the gauge gets unloaded immediately after loading.
The "panel.cfg" should be OK, I keep in unchanged and the gauge is described as follows:
Code:
[Vcockpit01]
gauge11=Gauge2!GaugeTwo, 0,0

Any idea what's wrong?
 
Attached is a sourcecode, including a DLL project and a gauge.

BTW previously I found many other issues with FSX. Say, when getting a module handle the GetModuleHandle()/GetModuleHandleEx() works with some DLLs, but refuses to do so with some others - returns NULL, while GetLastError gives 0x0000007E.
Could not find any significant difference in projects.
Only the LoadLibrary() could help.
 

Attachments

DONT use LoadLibrary. Wont help you. Also, depending on the gauge list in your panel cfg, you may need to keep calling GetModuleHandleEx until you get a valid handle because those gauges might only be loading after your gauge initialization occurs.
 
Any idea what's wrong?

Yes. In this section:

IFadec* pFadec = ::GetFadec();

Probably GetFadec() is not returning a new object but instead the pointer of an existing one.

If that's the case then in this section:

pFadec->Release();

the remote object is destroyed, hence the dll failure.
Check using pFadec = NULL;

Tom
 
No the data doesn't have to be declared that way at all.

OK, I went a bit further because you could share variables accross processes which was not in question in the first place however I personally use for FSX as well.

Anyway, I still prefer to communicate between DLLs using API & vtable technique (used by COM concept and SDK of Prepar3D 2.x) rather than sharing just data. They can be stand-alone gauges however you can create API to control & customize them from outside. I guess it's a question of preference rather than what's the best choice. Performance is not an issue here.

'fsx.exe': Loaded 'F:\FSX\SimObjects\Airplanes\BS\Panel\Gauge2.dll', No symbols loaded.
'fsx.exe': Unloaded 'F:\FSX\SimObjects\Airplanes\BS\Panel\Gauge2.dll'

How you link one DLL to another ? using static linking (lib) ? apparently FSX for some reason unknown to me does not like linking to some external DLLs, so it unloads after loading it. At least this is what I experienced when tried to link my gauge to some external DLLs. Try to unlink it and share the IFadec* using GetModuleHandleEx, fsx variable or other FSX technique.

Normally to overcome this "Unloading" I use LoadLibary .... and use GetProcAdress for exported function the way Naruto explained but this is only valid when my gauge loads another DLL rather than multiple gauges "talking" to each other.
 
Last edited:
DONT use LoadLibrary. Wont help you. Also, depending on the gauge list in your panel cfg, you may need to keep calling GetModuleHandleEx until you get a valid handle because those gauges might only be loading after your gauge initialization occurs.
Why don't? The LoadLibrary already returns a proper value.
As for GetModuleHandleEx() I also checked its return value after the sim is loaded and got the same NULL value.
Update: that's really weird but I tried the same code on the same DLL today, the GetModuleHandleEx() worked well and returned the proper handle! Kind of miracle, lol.

Yes. In this section:
IFadec* pFadec = ::GetFadec();
Probably GetFadec() is not returning a new object but instead the pointer of an existing one.

If that's the case then in this section:
pFadec->Release();
the remote object is destroyed, hence the dll failure.
Check using pFadec = NULL;
Tom
At the very beginning I tried removing the memory allocation and putting "return NULL;", and it changed nothing.
But 1st of all, let me repeat that all the code is not being called at all. That is, the GetFadec() cannot return anything, because when the mentioned code with "pFadec" is present, magically the whole gauge is unloaded immediately after loading:
Code:
'fsx.exe': Loaded 'F:\FSX\SimObjects\Airplanes\BS\Panel\Gauge2.dll', No symbols loaded.
'fsx.exe': Unloaded 'F:\FSX\SimObjects\Airplanes\BS\Panel\Gauge2.dll'

How you link one DLL to another ? using static linking (lib) ? apparently FSX for some reason unknown to me does not like linking to some external DLLs, so it unloads after loading it. At least this is what I experienced when tried to link my gauge to some external DLLs. Try to unlink it and share the IFadec* using GetModuleHandleEx, fsx variable or other FSX technique.
Hmm, it sounds interesting. For this very test project the DLL was linked using the corresponding LIB file (regardless of mentioned code with "pFadec" is present or not). That is, I included the LIB file name in the Linker tab, Additional Dependencies of Visual Studio project.
Ok, I'll try you suggestion, thanks a lot!

Normally to overcome this "Unloading" I use LoadLibary .... and use GetProcAdress for exported function the way Naruto explained but this is only valid when my gauge loads another DLL rather than multiple gauges "talking" to each other.
What do you do in case of multiple gauges "talking" to each other?
 
The LoadLibrary call creates an entirely new instance of your dll. If its a gauge that is loaded by FSX then you don't want to have 2 instances running around. GetModuleHandleEx gets you the handle of the dll IF it has been loaded already by the sim.
 
(regardless of mentioned code with "pFadec" is present or not

please note, when you specify lib file but you do not use any function from the dll, then the linker does not link it (i.e. does not create dependency for that DLL). So my bet is, replace the static linking with the dynamic one and Unloading should not happen.

You cannnot use LoadLibrary for a gauge file as it has to be loaded by FSX to initiate ImportTable. As Naruto pointed out, use GetModuleHandle as the gauge should be already loaded if you configure panel.cfg correctly.

What do you do in case of multiple gauges "talking" to each other?

I use GetModuleHandle instead of LoadLibrary ;)
 
Back
Top