[C++] Gauge Init/Deinit, Callback INOP

For topics related to the creation of simulation objects (SimObjects). This includes development of aircraft, ground, and maritime vehicles.
Post Reply
mattychays
Posts: 5
Joined: Sat Sep 29, 2018 10:10 pm

[C++] Gauge Init/Deinit, Callback INOP

Post by mattychays »

Gents,

I've gotta throw in the towel and ask for some help. I'm currently developing a gauge suite for Prepar3D V4 and using the PDK and RenderToTexture to render the gauges. (I've done this sucessfully). The thing I don't like about that approach is that the module is loaded with the sim and it makes it more cumbersome to get to LVars (even though they have added a newer system for that). What I am going to do know is initialize the PDK from a "system" gauge that manages all of the variables. I've done a lot of reading and built a test gauge to learn the implementation.

Thus far, the gauge will load (I can see the blank BMP in the cockpit), however the module_init, module_deinit, and Gauge Callback do not seem to be called. Excuse the test implementation not being the cleanest, when I learned to code in college I developed a habit pattern where I take really small chunks and make them work so I can understand the implementation. This is just a barebones gauge with a simple text log so I can study where everything is happening and plan out a more organized code base when I start implementing SimConnect and DirectX stuff.

I am using Visual Studio 2017 but compiling with the 2015 tools.

Here's where I've gotten so far:

Resource Files included (Visual Studio made a pretty ugly file, I cleaned those out and used the code from the SDK sample. Is there a better way to do this?)
The Gauge Compiles ✓
There is no errors logged in the content log from P3D (there was a few at first but it's because I wasn't using a 64 bit pointer) ✓
The Gauge BMP renders in the Cockpit ✓

What am I missing here? I attached the code below.

Is there a way to make the gauge completely invisible so it can solely handle logic?
#include "gauges.h"
#include "resource.h"
#include <fstream>

#define GAUGE_NAME "WindTunnel"
#define GAUGEHDR_VAR_NAME gaugehdr_WindTunnel
#define GAUGE_W 100

// Set up gauge header
char windtunnel_gauge_name[] = GAUGE_NAME;
extern PELEMENT_HEADER element_list;
extern MOUSERECT gauge_mouse_rect[];

GAUGE_HEADER_FS700(GAUGE_W, windtunnel_gauge_name, &element_list, gauge_mouse_rect, 0, 0, 0, 0);

MAKE_STATIC
(
windtunnel_image,
BMP_BACKGROUND,
NULL,
NULL,
IMAGE_USE_BRIGHT | IMAGE_CREATE_DIBSECTION | IMAGE_USE_ALPHA,
0,
0, 0
)

PELEMENT_HEADER element_list = &windtunnel_image.header;

MOUSE_BEGIN(gauge_mouse_rect, HELP_NONE, 0, 0)
MOUSE_END

#undef GAUGE_NAME
#undef GAUGEHDR_VAR_NAME
#undef GAUGE_H
#undef GAUGE_W

//Gauge DLL Initialization Definitions
void FSAPI module_init(void);
void FSAPI module_deinit(void);

GAUGESIMPORT ImportTable = {
{ 0x0000000F, (PPANELS)NULL },
{ 0x00000000, NULL }
};

GAUGESLINKAGE Linkage =
{
0x00000013,
module_init,
module_deinit,
0,
0,
FS9LINK_VERSION,
{&gaugehdr_WindTunnel,0}
};

//Gauge DLL Intilization (start)
void FSAPI module_init(void)
{
std::ofstream logfile;
logfile.open("cppGauge_Log.txt");
logfile << "Gauge Opened";
logfile.close();
}
//Gauge DLL Deinitalize (stop)
void FSAPI module_deinit(void)
{
std::ofstream logfile;
logfile.open("cppGauge_Log.txt");
logfile << "Gauge Closed";
logfile.close();
};

//Gauge Callback to handle Gauge Events
void FSAPI gaugeCallback(PGAUGEHDR pgauge, SINT32 service_id, UINT_PTR extra_data)
{
switch (service_id)
{
case PANEL_SERVICE_PRE_UPDATE:
std::ofstream logfile;
logfile.open("Log.txt");
logfile << "PRE_UPDATE CALLED";
logfile.close();
break;
}
}
SimonRobbins
Posts: 45
Joined: Sun Nov 27, 2011 11:13 am

Re: [C++] Gauge Init/Deinit, Callback INOP

Post by SimonRobbins »

You don't refer to your callback in the gauge macro. Try this to get the callback working:

Code: Select all

GAUGE_HEADER_FS700(GAUGE_W, windtunnel_gauge_name, &element_list, gauge_mouse_rect, gaugeCallback, 0, 0, 0);
Regards,

Si
Post Reply