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

P3D v3 [RESOLVED] Issues Loading First C++ Gauge

Messages
6
Country
unitedstates
Hello,

The past couple days I've been trying to make an effort to create gauges for Prepar3D V3 using Dai Griffith's latest sd2gau38 documentation and samples but I've been reluctant to post a help thread.
After a couple attempts, I got the gauge project to compile, with identical Visual Studio settings as the examples within the pdf that are provided; however the gauges will not load into P3D and I cannot find a reasonable explanation, or any good ways to go about debugging.

For my first gauge, I kept it simple. One master gauge class and a singular subgauge just for testing purposes.
The goal was to create a simple fuel gauge and work my way from there, but that task has proven itself more confusing than expected.

simgauges.cpp (master)
C++:
#include "fsxgauges_sp2.h"
#include "simgauges.h"

#define GAUGE_NAME "fuelgauge\0"
#define    GAUGEHDR_VAR_NAME    fuelgaugehdr
#define GAUGE_W 200

#include "fuelgauge.c"

GAUGE_TABLE_BEGIN()
    GAUGE_TABLE_ENTRY(&fuelgaugehdr)
GAUGE_TABLE_END()

simgauges.h
C++:
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_WARNINGS
#define         VERSION_MAJOR           1
#define         VERSION_MINOR           0
#define         VERSION_BUILD           0

#define        lita(arg) #arg
#define        xlita(arg) lita(arg)
#define        cat3(w,x,z) w##.##x##.##z##\000
#define        xcat3(w,x,z) cat3(w,x,z)
#define        VERSION_STRING xlita(xcat3(VERSION_MAJOR,VERSION_MINOR,VERSION_BUILD))

#ifndef        VS_VERSION_INFO
#define        VS_VERSION_INFO        0x0001
#endif

#define        BMP_BACKGROUND        0x1000
#define        BMP_NEEDLE            0x1003

fuelgauge.c
C:
char fuelgauge_name[] = GAUGE_NAME;
extern PELEMENT_HEADER fuel_list;
extern MOUSERECT fuel_mouse_rect[];

GAUGE_HEADER_FS700(GAUGE_W, fuelgauge_name, &fuel_list,
    fuel_mouse_rect, 0, 0, 0, 0);

#define GAUGE_MIN 0
#define GAUGE_MAX 26

NONLINEARITY fuel_nonlinearity[] =
{
    { { 96, 621 }, 0, 0 },
    { { 45, 513 }, 2, 0 },
    { { 29, 410 }, 4, 0 },
    { { 38, 315 }, 6, 0 },
    { { 73, 220 }, 8, 0 },
    { { 129, 145 }, 10, 0 },
    { { 219, 75 }, 12, 0 },
    { { 342, 33 }, 14, 0 },
    { { 457, 31 }, 16, 0 },
    { { 594, 74 }, 18, 0 },
    { { 682, 150 }, 20, 0 },
    { { 741, 226 }, 22, 0 },
    { { 775, 326 }, 24, 0 },
    { { 781, 417 }, 26, 0 },
};

FAILURE_RECORD fuel_fail[] = {
    { FAIL_SYSTEM_ELECTRICAL_PANELS, FAIL_ACTION_ZERO },
    { FAIL_GAUGE_FUEL_INDICATORS, FAIL_ACTION_FREEZE },
    { FAIL_NONE, FAIL_ACTION_NONE }
};

MODULE_VAR fuelLev = { FUEL_TANK_RIGHT_MAIN_LEVEL };

FLOAT64 FSAPI fuel_needle_cb(PELEMENT_NEEDLE pelement)
{
    FLOAT64 val = pelement->source_var.var_value.n;

    if (val > GAUGE_MAX)
        val = GAUGE_MAX;
    else if (val < GAUGE_MIN)
        val = GAUGE_MIN;

    return val;
}

MAKE_NEEDLE
(
    fuel_needle,
    BMP_NEEDLE,
    NULL,
    fuel_fail,
    IMAGE_USE_TRANSPARENCY | IMAGE_USE_ERASE | IMAGE_BILINEAR_COLOR,
    0,
    150, 150,
    6, 12,
    TOTAL_FUEL_QUANTITY_GALLONS, fuel_needle_cb,
    fuel_nonlinearity,
    6
)

PELEMENT_HEADER fuel_needle_list[] =
{
    (PELEMENT_HEADER)&fuel_needle,
    NULL
};

MAKE_STATIC
(
    fuel_background,
    BMP_BACKGROUND,
    &fuel_needle_list,
    fuel_fail,
    IMAGE_USE_TRANSPARENCY,
    0,
    9, 0
)
PELEMENT_HEADER fuel_list = &fuel_background.header;

MOUSE_BEGIN(fuel_mouse_rect, HELPID_GAUGE_FUEL, 0, 0)
MOUSE_END

#undef GAUGE_NAME
#undef    GAUGEHDR_VAR_NAME 
#undef GAUGE_W

resources.rc
Code:
#include    "simgauges.h"

VS_VERSION_INFO VERSIONINFO
FILEVERSION VERSION_MAJOR,VERSION_MINOR,0,VERSION_BUILD
PRODUCTVERSION VERSION_MAJOR,VERSION_MINOR,0,VERSION_BUILD
FILEFLAGSMASK 0x3fL
FILEFLAGS 0x0L
FILEOS 0x10004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "CompanyName", "Company name\0"
            VALUE "FileDescription", "Prepar3d Gauges\0"
            VALUE "FileVersion", VERSION_STRING
            VALUE "LegalCopyright", "Copyright info\0"
            VALUE "ProductName", "TestGauges\0"
            VALUE "ProductVersion", VERSION_STRING
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END

BMP_BACKGROUND        BITMAP    DISCARDABLE        "images\\background.bmp"
BMP_NEEDLE        BITMAP    DISCARDABLE        "images\\needle.bmp"

That's it for the gauge project code. Here's the section in my panel.cfg that includes the gauge:
Code:
[Window Titles]
Window07=Gauges Window

[Window07]
size_mm=400,400
gauge00=TestGauges!fuelgauge, 0, 0, 100, 100

I've titled all of the exported files accordingly for the panel configuration as well
-TestGauges.dll, TestGauges.exp, TestGauges.lib
These three files are located in the Prepar3d V3/gauges/ folder.

If there's something I might have missed or completely looked over, please feel free to let me know. I'm happy to provide as much additional information as needed.
 
Last edited:
Okay, so it was a bit of a dumb mistake on my part, but I'll post the solution in case anyone else comes across this same issue.
I was exporting the gauges as a 64 bit DLL, and had not taken into consideration the fact that P3D V3 doesn't support 64 bit gauges.
This thread can be closed.
 
Rather than put your gauges in the main \gauges folder, put them in the \panel folder. It keeps everything together and makes them easier to find! :)
 
Rather than put your gauges in the main \gauges folder, put them in the \panel folder. It keeps everything together and makes them easier to find! :)

I'll definitely go ahead and do that, I appreciate it.

I only have one more small concern with my gauges. I've been able to successfully add a second gauge to the master source file (which loads and works perfectly), but after I've added my third gauge for vertical speed, Prepar3D decides to crash after the splash screen on startup.
I checked the ContentErrorLog.txt file, and there appears to be no errors when the gauges are loaded, but the scenerio selection screen never pops up.
The strange part is, I've compared the failing gauge with my two others and they appear to be identical syntactically.

What I assumed might be the issue was the organization of my resource file and their hexadecimal assignments, so I organized everything sequentially to match the order of declarations in my main header file to no avail.
Is there something that I might be missing with multigauge projects that might cause my third gauge from loading?
Thanks.

EDIT: Discovered it can't be an issue with how I wrote the third gauge, as I tried commenting out one of my previous ones that were loaded onto the gauge table, and it loaded fine.
Sort of a strange behavior that the Prepar3D only loads the gauges when there's only one or two entered into the gauge table.
 
Last edited:
I wouldn't write off a problem in the code just yet. Remove the third gauge completely from the original code and add it to a project of its own. Now see what happens to the original two and the new third one when you try to load them. Also, cross-check the resource names between the .rc and the .h file. The compiler will find a missing bitmap if the resource names are the same, but if you have a resource name in the .h file with no corresponding resource name in the .rc file, the gauge will compile successfully. That definately upsets the sim.
 
Back
Top