[PDK] How to get Custom Variable ? (C:<Module Name>:<Variable>)

a8325811
Posts: 9
Joined: Mon Dec 16, 2019 7:25 am

[PDK] How to get Custom Variable ? (C:<Module Name>:<Variable>)

Postby a8325811 » Mon Dec 16, 2019 7:58 am

Hi, I want to get the custom variable like this.

Code: Select all

C:POI:SelectedTargetName
But I can't figure our how to get this variable in C++ PDK project ?

Does anyone know ? Thanks.

JB3DG
Posts: 488
Joined: Mon Jan 09, 2012 6:44 pm

Re: [PDK] How to get Custom Variable ? (C:<Module Name>:<Variable>)

Postby JB3DG » Mon Dec 16, 2019 9:42 am

Jonathan Bleeker
Milviz systems dev

Formerly known as Naruto-kun

a8325811
Posts: 9
Joined: Mon Dec 16, 2019 7:25 am

Re: [PDK] How to get Custom Variable ? (C:<Module Name>:<Variable>)

Postby a8325811 » Tue Dec 17, 2019 1:37 am

Hi, thanks your reply, I try this method, but when I compile the code, there some warning show.

Code: Select all

LNK2020 unresolved token ImportTable LNK2001 unresolved external symbol ImportTable LNK1120 2 unresolved externals
I have try some solution I found, like add .lib file to Linker, but I can't find like gauges.lib file in PDK foldor.
Do you have any idea about this ? Thanks

JB3DG
Posts: 488
Joined: Mon Jan 09, 2012 6:44 pm

Re: [PDK] How to get Custom Variable ? (C:<Module Name>:<Variable>)

Postby JB3DG » Tue Dec 17, 2019 8:51 am

There isn't a gauges.lib. You got something like this in your code somewhere?
GAUGESIMPORT ImportTable = {
{ 0x0000000F, (PPANELS)NULL },
{ 0x00000000, NULL }
};

GAUGESLINKAGE Linkage =
{
0x00000013,
module_init,
module_deinit,
0,
0,
FS9LINK_VERSION,
{
&gaugehdr_ACM,
&gaugehdr_Sys,
0
}
};
Jonathan Bleeker
Milviz systems dev

Formerly known as Naruto-kun

a8325811
Posts: 9
Joined: Mon Dec 16, 2019 7:25 am

Re: [PDK] How to get Custom Variable ? (C:<Module Name>:<Variable>)

Postby a8325811 » Tue Dec 17, 2019 9:50 am

I add this in my code.

Code: Select all

#include "gauges.h" void DataCollector::OnFrame(IParameterListV400* pParams) { IPanelCCallback *pPCC_TPUtil = panel_get_registered_c_callback("VRSTP_Util"); IAircraftCCallback *pACC_TPUtil = pPCC_TPUtil->CreateAircraftCCallback(0); IGaugeCCallback *pGCC_TPUtil = pACC_TPUtil->CreateGaugeCCallback(); };
And I check all code, only in gauges.h file have these ImportTable thing, like this.

Code: Select all

#define panel_get_registered_c_callback (ImportTable.PANELSentry.fnptr->panel_get_registered_c_callback) #define panel_get_aircraft_c_callback (ImportTable.PANELSentry.fnptr->panel_get_aircraft_c_callback) #define send_key_event (ImportTable.PANELSentry.fnptr->send_key_event) #define register_key_event_handler (ImportTable.PANELSentry.fnptr->register_key_event_handler) #define unregister_key_event_handler (ImportTable.PANELSentry.fnptr->unregister_key_event_handler) #define process_shared_event_out ( ImportTable.PANELSentry.fnptr->process_shared_event_out) #define is_master ( ImportTable.PANELSentry.fnptr->is_master) #define set_named_variable_value_sync (ImportTable.PANELSentry.fnptr->set_named_variable_value_sync) #define set_named_variable_sync_enabled (ImportTable.PANELSentry.fnptr->set_named_variable_sync_enabled) #define get_event_description (ImportTable.PANELSentry.fnptr->get_event_description) #define get_event_token_string (ImportTable.PANELSentry.fnptr->get_event_token_string) #define query_pdk (ImportTable.PANELSentry.fnptr->query_pdk) #define get_event_count (ImportTable.PANELSentry.fnptr->get_event_count) #define get_event_id_by_index (ImportTable.PANELSentry.fnptr->get_event_id_by_index) // This is the gauge's import table definition typedef struct GAUGESIMPORT { struct { ID fnID; PPANELS fnptr; }PANELSentry; struct { ID fnID; PVOID fnptr; }nullentry; } GAUGESIMPORT, *PGAUGESIMPORT; EXTERN_C DECLSPEC_EXPORT GAUGESIMPORT ImportTable; #if defined(_MSC_VER) #pragma warning( push ) #pragma warning( disable:4200 ) #endif // This is the module's export table definition typedef struct GAUGESLINKAGE { FSLINKAGE PGAUGEHDR gauge_header_ptr[]; } GAUGESLINKAGE, *PGAUGESLINKAGE, **PPGAUGESLINKAGE; #if defined(_MSC_VER) #pragma warning( pop ) #endif EXTERN_C DECLSPEC_EXPORT GAUGESLINKAGE Linkage;
Are this file shoud fix?

JB3DG
Posts: 488
Joined: Mon Jan 09, 2012 6:44 pm

Re: [PDK] How to get Custom Variable ? (C:<Module Name>:<Variable>)

Postby JB3DG » Tue Dec 17, 2019 4:32 pm

Are you running a C++ gauge or a C++ module loaded via the dll.xml?
Jonathan Bleeker
Milviz systems dev

Formerly known as Naruto-kun

a8325811
Posts: 9
Joined: Mon Dec 16, 2019 7:25 am

Re: [PDK] How to get Custom Variable ? (C:<Module Name>:<Variable>)

Postby a8325811 » Wed Dec 18, 2019 2:37 am

Are you running a C++ gauge or a C++ module loaded via the dll.xml?
I use the Official PDK C++ Example, DataHarvester.

So I not use dll.xml in my project.

JB3DG
Posts: 488
Joined: Mon Jan 09, 2012 6:44 pm

Re: [PDK] How to get Custom Variable ? (C:<Module Name>:<Variable>)

Postby JB3DG » Wed Dec 18, 2019 8:12 am

Look up the C: var module example in the SDK for how to set up the import table.
Jonathan Bleeker
Milviz systems dev

Formerly known as Naruto-kun

a8325811
Posts: 9
Joined: Mon Dec 16, 2019 7:25 am

Re: [PDK] How to get Custom Variable ? (C:<Module Name>:<Variable>)

Postby a8325811 » Thu Dec 19, 2019 7:36 am

Look up the C: var module example in the SDK for how to set up the import table.
Ok, I will look into it, and then report to you.

a8325811
Posts: 9
Joined: Mon Dec 16, 2019 7:25 am

Re: [PDK] How to get Custom Variable ? (C:<Module Name>:<Variable>)

Postby a8325811 » Tue Dec 24, 2019 9:57 am

Look up the C: var module example in the SDK for how to set up the import table.
Hi, here is my code.

Code: Select all

PPANELS Panels = NULL; GAUGESIMPORT ImportTable = { {0x0000000F, (PPANELS)NULL}, {0x00000000, NULL} }; My_DataCollector::My_DataCollector() { //Init ImportTable.PANELSentry.fnptr = (PPANELS)Panels; }; void My_DataCollector::OnFrame(IParameterListV400* pParams) { IPanelCCallback *pPCC_TPUtil = panel_get_registered_c_callback("VRSTP_Radar"); IAircraftCCallback *pACC_TPUtil = pPCC_TPUtil->CreateAircraftCCallback(0); IGaugeCCallback *pGCC_TPUtil = pACC_TPUtil->CreateGaugeCCallback(); SINT32 ID = 0; pPCC_TPUtil->ConvertStringToProperty("Mode4Code", &ID); FLOAT64 fReadVal = 0; pGCC_TPUtil->GetPropertyValue(ID, &fReadVal); };
Now, the compiler is fine, but new question come, when I load this dll into Prepar3D, the P3D will CTD, I try to do some debug with my code, finally I got some error message on visual studio.

Code: Select all

System.NullReferenceException: Object reference not set to an instance of an object.
Do you have any idea? thanks

JB3DG
Posts: 488
Joined: Mon Jan 09, 2012 6:44 pm

Re: [PDK] How to get Custom Variable ? (C:<Module Name>:<Variable>)

Postby JB3DG » Tue Dec 24, 2019 2:18 pm

You should have a DllStart or module_init function in your dll that the simulator calls on load. That's where you should do the panel pointer assignment.
Jonathan Bleeker
Milviz systems dev

Formerly known as Naruto-kun

a8325811
Posts: 9
Joined: Mon Dec 16, 2019 7:25 am

Re: [PDK] How to get Custom Variable ? (C:<Module Name>:<Variable>)

Postby a8325811 » Wed Dec 25, 2019 2:24 am

You should have a DllStart or module_init function in your dll that the simulator calls on load. That's where you should do the panel pointer assignment.
Yes, finally I got the custom variable, I also find you must add a .def file and set in linker, so P3D will know to set Panel pointer.

a8325811
Posts: 9
Joined: Mon Dec 16, 2019 7:25 am

Re: [PDK] How to get Custom Variable ? (C:<Module Name>:<Variable>)

Postby a8325811 » Wed Dec 25, 2019 2:32 am

Remark for other people who want get Custom variable, here is my solution.

1.First create a Dll project like before, and write something like this in file.

Code: Select all

#include "initpdk.h" #include "gauges.h" using namespace P3D; PPANELS Panels = NULL; GAUGESIMPORT ImportTable = { {0x0000000F, (PPANELS)NULL}, {0x00000000, NULL} }; extern "C" __declspec(dllexport) void __stdcall DLLStart(__in __notnull IPdk* pPdk) { if (pPdk != nullptr && NULL != Panels) { //The Panels pointer will get filled in during the loading process ImportTable.PANELSentry.fnptr = (PPANELS)Panels; //Start Your Program s_My_DataCollector = new My_DataCollector; } } extern "C" __declspec(dllexport) void __stdcall DLLStop(void) { //End Program delete s_My_DataCollector; }
2.Add a .def file to your project, and write this.

Code: Select all

LIBRARY EXPORTS Panels DLLStart DLLStop
3.Write this .def file into visual studio Linker\Input\Module Definition File.
(eg. myDefine.def)

4.Last, use this statement in your program to get custom variable.

Code: Select all

void My_DataCollector::Update(CComPtr<IBaseObjectV400> &userObj) { //Get Custom Variable IPanelCCallback *pPCC_TPUtil = panel_get_registered_c_callback("Module_Name"); IAircraftCCallback *pACC_TPUtil = pPCC_TPUtil->CreateAircraftCCallback(0); IGaugeCCallback *pGCC_TPUtil = pACC_TPUtil->CreateGaugeCCallback(); SINT32 ID = 0; pPCC_TPUtil->ConvertStringToProperty("Variable_Name", &ID); FLOAT64 fReadVal = 0; pGCC_TPUtil->GetPropertyValue(ID, &fReadVal); //This is what you want fReadVal; };

Hope these can help someone. And thanks again JB3DG help.


Return to “Software Development Kit (SDK) Questions”

Who is online

Users browsing this forum: Google [Bot] and 20 guests