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

Looking for Guidance in porting a XML Gauge to C++ (PAID)

Messages
9
I have a working XML Gauge for Prepar3d, and need to find a way to port it into a C++ solution (dll). All the gauge is doing is reading the Angle of Incidence and changing the image of the gauge depending on its value.
Thanks in advance.
 
This is a developer site. It is 100% opposed to piracy. You might want to change your avatar...
 
Seriously? I have never attacked a boat or a ship neither am I a pirate. Could you please explain me how you inferred that by looking at my avatar?
 
A skull and crossbones? How would anyone take your request seriously? This was sensible advice, not some sort of challenge. What you say, do and show in a public forum reflects on your character. You are asking for help. Why position yourself as some sort of pirate?
 
I take issue with your comment. The Gravatar image was done by a friend that I lost through tragic circumstances. We both worked in security. Hope you feel better now.
 
I have a working XML Gauge for Prepar3d, and need to find a way to port it into a C++ solution (dll). All the gauge is doing is reading the Angle of Incidence and changing the image of the gauge depending on its value.
Thanks in advance.
Which sim platform are you targeting?

Your best bet will likely be using claude.ai 3.5 Sonnet to do the conversion. I dropped in an FSX XML fuel gauge sample and while I've not dealt with gauges before claude is very robust on the programming side.

Others may need to verify if this is correct...

DigitalAviator said:
I need help to convert this FSX XML gauge code to MSFS C++ DLL gauge

<?xml version="1.0" encoding="UTF-8"?>
<SimBase.Document
Type="AceXML"
version="1,0"
id="Fuel Pressure Gauge">
<Descr>AceXML Document</Descr>
<SimGauge.Gauge id="Gauge" ArtDirectory="C:\Flight Simulator X\SDK\SimObject Creation Kit\Panels and Gauges SDK\XML Gauge samples">
<FloatPosition>0.000,0.000</FloatPosition>
<Size>100,80</Size>
<Image id="FuelPressureBackground.bmp" Name="FuelPressureBackground.bmp">
<Transparent>True</Transparent>
</Image>
<Element id="Element">
<FloatPosition>5.000,10.000</FloatPosition>
<GaugeText id="GaugeText">
<Bold>True</Bold>
<Fixed>True</Fixed>
<FontFace>ARIAL</FontFace>
<FontColor>gold</FontColor>
<FontHeight>13</FontHeight>
<GaugeString>Fuel Pressure</GaugeString>
<HilightColor>blue</HilightColor>
<Length>32</Length>
<Size>90,15</Size>
<Transparent>True</Transparent>
<VerticalAlign>CENTER</VerticalAlign>
</GaugeText>
</Element>
<Element id="Element">
<FloatPosition>5.000,40.000</FloatPosition>
<Rectangle id="Rectangle">
<LineWidth>1</LineWidth>
<Width>90</Width>
<Height>24</Height>
<LineColor>darkslateblue</LineColor>
<FillColor>black</FillColor>
</Rectangle>
</Element>
<Element id="Element">
<FloatPosition>10.000,44.000</FloatPosition>
<GaugeText id="GaugeText">
<FontFace>COURIER</FontFace>
<FontColor>red</FontColor>
<FontHeight>16</FontHeight>
<GaugeString>%( (A:GENERAL ENG FUEL PRESSURE:1, psi) )%!09d!</GaugeString>
<Length>9</Length>
<Size>90,16</Size>
<Transparent>True</Transparent>
<VerticalAlign>CENTER</VerticalAlign>
</GaugeText>
</Element>
</SimGauge.Gauge>
</SimBase.Document>

ClaudeAI said:
To convert this FSX XML gauge code to an MSFS C++ DLL gauge, we'll need to create a C++ class that inherits from the appropriate MSFS gauge base class and implement the necessary functionality. Here's a basic structure for the converted gauge:

Code:
#include <MSFS/MSFS.h>
#include <MSFS/MSFS_Render.h>
#include <MSFS/MSFS_WindowsTypes.h>
#include <MSFS/MSFS_SDL.h>
#include <SimConnect.h>

class FuelPressureGauge : public BaseGauge {
private:
    // Texture handles
    MSFS::Texture* m_backgroundTexture;

    // Font handles
    MSFS::Font* m_titleFont;
    MSFS::Font* m_valueFont;

    // SimConnect variables
    HANDLE m_hSimConnect;
    float m_fuelPressure;

public:
    FuelPressureGauge() : BaseGauge(), m_backgroundTexture(nullptr), m_titleFont(nullptr), m_valueFont(nullptr), m_hSimConnect(nullptr), m_fuelPressure(0.0f) {}

    virtual bool Initialize() override {
        // Load textures
        m_backgroundTexture = MSFS::Texture::CreateFromFile("FuelPressureBackground.png");

        // Create fonts
        m_titleFont = MSFS::Font::CreateInstance("Arial", 13, MSFS::FONT_WEIGHT_BOLD);
        m_valueFont = MSFS::Font::CreateInstance("Courier New", 16, MSFS::FONT_WEIGHT_NORMAL);

        // Initialize SimConnect
        if (SUCCEEDED(SimConnect_Open(&m_hSimConnect, "Fuel Pressure Gauge", nullptr, 0, 0, 0))) {
            // Add data definition for fuel pressure
            SimConnect_AddToDataDefinition(m_hSimConnect, 0, "GENERAL ENG FUEL PRESSURE:1", "psi");
            // Request data
            SimConnect_RequestDataOnSimObject(m_hSimConnect, 0, 0, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_SIM_FRAME);
        }

        return true;
    }

    virtual void Update() override {
        // Process SimConnect messages
        SimConnect_CallDispatch(m_hSimConnect, DispatchProc, this);
    }

    virtual void Draw() override {
        // Draw background
        if (m_backgroundTexture) {
            MSFS::DrawContext::SetTexture(m_backgroundTexture);
            MSFS::DrawContext::DrawRectangle(0, 0, 100, 80);
        }

        // Draw title
        if (m_titleFont) {
            MSFS::DrawContext::SetFont(m_titleFont);
            MSFS::DrawContext::SetColor(1.0f, 0.84f, 0.0f, 1.0f); // Gold color
            MSFS::DrawContext::DrawText(5, 10, "Fuel Pressure", 90, 15, MSFS::TEXT_ALIGNMENT_CENTER, MSFS::TEXT_ALIGNMENT_CENTER);
        }

        // Draw value background
        MSFS::DrawContext::SetColor(0.0f, 0.0f, 0.0f, 1.0f); // Black
        MSFS::DrawContext::DrawRectangle(5, 40, 90, 24);

        // Draw value border
        MSFS::DrawContext::SetColor(0.28f, 0.24f, 0.55f, 1.0f); // Dark slate blue
        MSFS::DrawContext::DrawRectangleOutline(5, 40, 90, 24, 1);

        // Draw value
        if (m_valueFont) {
            MSFS::DrawContext::SetFont(m_valueFont);
            MSFS::DrawContext::SetColor(1.0f, 0.0f, 0.0f, 1.0f); // Red color
            char valueText[10];
            snprintf(valueText, sizeof(valueText), "%09.2f", m_fuelPressure);
            MSFS::DrawContext::DrawText(10, 44, valueText, 80, 16, MSFS::TEXT_ALIGNMENT_LEFT, MSFS::TEXT_ALIGNMENT_CENTER);
        }
    }

    virtual void Destroy() override {
        // Clean up resources
        if (m_backgroundTexture) {
            delete m_backgroundTexture;
        }
        if (m_titleFont) {
            delete m_titleFont;
        }
        if (m_valueFont) {
            delete m_valueFont;
        }
        if (m_hSimConnect) {
            SimConnect_Close(m_hSimConnect);
        }
    }

private:
    static void CALLBACK DispatchProc(SIMCONNECT_RECV* pData, DWORD cbData, void* pContext) {
        FuelPressureGauge* pThis = static_cast<FuelPressureGauge*>(pContext);
        pThis->ProcessSimConnectMessage(pData, cbData);
    }

    void ProcessSimConnectMessage(SIMCONNECT_RECV* pData, DWORD cbData) {
        switch (pData->dwID) {
            case SIMCONNECT_RECV_ID_SIMOBJECT_DATA:
            {
                SIMCONNECT_RECV_SIMOBJECT_DATA* pObjData = static_cast<SIMCONNECT_RECV_SIMOBJECT_DATA*>(pData);
                if (pObjData->dwRequestID == 0) {
                    m_fuelPressure = *((float*)&pObjData->dwData);
                }
                break;
            }
        }
    }
};

// Export the gauge creation function
extern "C" MSFS_CALLBACK FuelPressureGauge* CreateGauge() {
    return new FuelPressureGauge();
}

This C++ code creates a FuelPressureGauge class that inherits from BaseGauge. Here's a breakdown of the conversion:


  1. The gauge size is set to 100x80 pixels, matching the XML.
  2. The background image is loaded as a texture.
  3. Fonts are created for the title and value text.
  4. SimConnect is used to retrieve the fuel pressure data.
  5. The Draw method handles rendering the gauge, including the background, title, and fuel pressure value.
  6. The fuel pressure value is updated through SimConnect in the Update method.

To compile this into a DLL for MSFS, you'll need to:


  1. Set up the MSFS SDK and ensure you have the necessary include directories and library files.
  2. Create a project in your preferred C++ IDE or use CMake to generate the project files.
  3. Compile the code as a DLL.
  4. Create an XML layout file that references this DLL and place it in your aircraft's panel folder.

Note that you may need to adjust some details, such as file paths and exact color values, to match your specific requirements and MSFS conventions.
 
Thank you for your response. I am primarily targeting Prepar3d V5, and will give Claude a shot.
 
Thank you for your response. I am primarily targeting Prepar3d V5, and will give Claude a shot.
I’ve been totally blown away by Claude this last week. It generates windows power tools scripts perfectly. I’ve been working with it all day (subscription version) and pulled 4000 lines of information from every aircraft I have installed.

I need to test it on porting my old Visual Basic program to C# and see how it does. GPT failed due to limitations. It’s really good at debugging it’s own code too if you find an issue. So fast too.
 
Interesting.
ChatGPT worked fine for me, except for Prepar3d, it sometimes generated incorrect code.
I will definitely take a look at Claude, thank you for that suggestion.
 
Back
Top