C: Launching an external .exe from within a gauge

From FSDeveloper Wiki
Revision as of 07:16, 20 August 2018 by Dragonflightdesign (talk | contribs) (Created page with "This short piece of code allows you to launch an external executable (.exe file) and detect when the program has been started. Place the code inside the gauge callback. //-...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This short piece of code allows you to launch an external executable (.exe file) and detect when the program has been started. Place the code inside the gauge callback.


//---------------------------------------------------------------------------
// Gauge callback
//---------------------------------------------------------------------------
void FSAPI  aircraft_config_update(PGAUGEHDR pgauge, int service_id, PUSERDATA extra_data)
{
  HINSTANCE ret = 0;
  static int retSuccess = 0;
 
  switch (service_id)
  {
   case PANEL_SERVICE_PRE_UPDATE:

     if (!retSuccess)
     {
       // Try to open NotePad
       ret = ShellExecute(NULL, "open", "c:\\windows\\notepad.exe", NULL, NULL, SW_SHOWNORMAL);
       // If ret > 32 i.e. success then set retSuccess to 1
       if (int(ret) > 32)retSuccess = 1;
     }

Note the use of PUSERDATA in the method header. This allows the code to be FSX / P3D agnostic but you must have the correct #ifdef somewhere in your project.

#ifdef _64BIT
  #define PUSERDATA UINT_PTR
 (etc.)
#else
  #define PUSERDATA UINT32
  (etc.)
#endif