FSXA [Compiled OK]Converting a 32 bit C++ gauge to P3Dv4

#1
Hello there,

Hello there !

Following the release of the Damage Mod for Flight1’s BN-2 Islander, I have been asked if the mod (designed for FSXA) was available for P3Dv4. The XML gauges should work OK, Doug’s fuel, config and sound gauges already exist for P3Dv4, so it all falls down to my two C++ gauges intercepting the throttle or pitch lever positions.
Is there a way to recompile the source code so that the gauges work in P3Dv4? I suppose so, but I am struggling to find a tutorial here or over the wide web.

Have a nice day
 

DragonflightDesign

Resource contributor
#2
https://www.fsdeveloper.com/forum/resources/fsx-p3d-and-cfs3-gauge-creation-tutorial-rev-36.206/

There's a section on setting up Visual Studio for compiling 64-bit gauges. In your gauges you will need to change the gauge callback header from UINT32 to UINT_PTR e.g.
Code:
void FSAPI aircraft_config_update(PGAUGEHDR pgauge, int service_id, UINT_PTR extra_data)
The other approach to this is to use an #ifdef e.g.
Code:
#ifdef _64BIT
    #include "p3dv4_gauges.h"
    #define PUSERDATA UINT_PTR
    #include "simconnect\64\SimConnect.h"
#else
    #include "fsxgauges_sp2.h"
    #define PUSERDATA UINT32
    #include "simconnect\fsx\SimConnect.h"
#endif
and change the gauge callback header to
Code:
void FSAPI aircraft_config_update(PGAUGEHDR pgauge, int service_id, PUSERDATA extra_data)
 
Last edited:
#4
Two additional questions :
- Is compiling a FSX SDK based gauge with a 64bits setting (and your proposed header change) enough to have it work in P3Dv4, or do I need to install the P3Dv4 SDK and compile from it ?
- Is the header change the only "code" modification required?
 

ddawson

Resource contributor
#5
Two additional questions :
- Is compiling a FSX SDK based gauge with a 64bits setting (and your proposed header change) enough to have it work in P3Dv4, or do I need to install the P3Dv4 SDK and compile from it ?
- Is the header change the only "code" modification required?
You will need to use the P3Dv4 version of gauges.h
Also, if you are using SimConnect in the gauge, make sure you use the version of simconnect.h and simconnect.lib that are included with the P3Dv4 SDK.
 

DragonflightDesign

Resource contributor
#6
To add to Doug's response - see also the #ifdef statement I posted in my initial reply - this switches between FSX and P3D and the required gauges and simconnect header files. You may need to add paths to the #ifdef statement depending on your setup.
 
#7
Hi,

Still so much to learn I am afraid.
I have set VS2017 and my project as per stated in Dai’s tutorial, and have gone the UINT_PTR way.
I have updated the inc and lib paths in the project settings to the P3Dv4 inc and lib folders.
I have added the v4 gauges.h and simconnect.h to the project.
I have added SimConnect.lib to the linker’s command line.
But all I am getting is 8 lnk2001 errors : unresolevd external symbol. They are all related to SimConnect « functions » eg simconnect_SetNotificationGroupPriority.

Is there another obvious item rookie-me has forgotten to set right?

PS: I have installed P3Dv4’s SDK, but I don’t have the sim. Is it of any importance?
 

JB3DG

Resource contributor
#8
You need to use separate SimConnect.h and lib files for x64. Also, v4 uses separate release and debug libs. I would keep the lib out of the linker's command line and use #pragma comment linking instead.

Here is what I use in most of my projects:

C++:
#ifdef _M_X64
#include "lx64\\SimConnect.h"
#ifdef _DEBUG
#pragma comment(lib, "lx64\\SimConnectDebug.lib")
#else
#pragma comment(lib, "lx64\\SimConnect.lib")
#endif
#else
#include "SimConnect.h"
#pragma comment(lib, "SimConnect.lib")
#endif
 

DragonflightDesign

Resource contributor
#9
Never thought about using #pragma commenting! :) I do have an #ifdef _DEBUG switching statement in my code but never thought to post it with the original example. My bad - I should have done.

And... I've said it before, but thanks for the original #ifdef _64BIT statement. You have no idea how much grief that has saved me!
 
#11
Case closed! (at least as long as the compilation is concerned).
I just had to delete 32-bit gauges.h and simconnect.h/.lib files inside the project folder, so that the x64 ones could be used for compiling.
Programming is such a blast! :laughing:
 
#12
even you solved compiling with deleting 32-bit gauge.h and paste x64 gauge.h, you did long way though.
I did what JB3DG did, and I just need select x64 or x32 on solution platform just like flip my hand, then compile.
 
Top