Using this code as your instructions just added a FSUIPC_Read function before Close:
#include <iostream>
#include <windows.h>
#include "FSUIPC_User64.h"
#include <iomanip>
using namespace std;
int main()
{
DWORD dwResult;
if (FSUIPC_Open(SIM_ANY, &dwResult))
{
std::cout << "Connected to FSUIPC" << std::endl;
double newLvarValue = 1.0; // The value you want to set
// Step 1: Write the new LVAR value to user offset 0x66C0
if (!FSUIPC_Write(0x66C0, sizeof(newLvarValue), &newLvarValue, &dwResult))
{
std::cout << "Failed to write new LVAR value to offset 0x66C0" << std::endl;
}
// Step 2: Write the offset address (0x66C0) and format specifier (0 for double) to 0x0D6C
DWORD param = 0x66C00000; // 0x66C0 offset + format specifier (0 = double)
if (!FSUIPC_Write(0x0D6C, sizeof(param), ¶m, &dwResult))
{
std::cout << "Failed to write parameter to offset 0x0D6C" << std::endl;
}
// Step 3: Write the LVAR command "::ASD_SWITCH_EXT_POWER" to 0x0D70
const char lvarCommand[] = "::ASD_SWITCH_EXT_POWER";
if (!FSUIPC_Write(0x0D70, sizeof(lvarCommand), (void*)lvarCommand, &dwResult))
{
std::cout << "Failed to write LVAR command to offset 0x0D70" << std::endl;
}
// Step 4: Process the writes
if (!FSUIPC_Process(&dwResult))
{
std::cout << "FSUIPC process failed" << std::endl;
}
else
{
std::cout << "LVAR write command sent successfully" << std::endl;
}
// Step 5: Read back the value from 0x66C0 to confirm the change
double readBackValue = 0.0;
if (FSUIPC_Read(0x66C0, sizeof(readBackValue), &readBackValue, &dwResult))
{
FSUIPC_Process(&dwResult);
std::cout << "LVAR ASD_SWITCH_EXT_POWER updated to: " << readBackValue << std::endl;
}
else
{
std::cout << "Failed to read back LVAR value" << std::endl;
}
FSUIPC_Close();
}
else
{
std::cout << "Failed to connect to FSUIPC" << std::endl;
}
}
This results in :
Connected to FSUIPC
LVAR write command sent successfully
LVAR ASD_SWITCH_EXT_POWER updated to: 1
But the switch in the simulator doesn't change, I am sure that the switch named ASD_SWITCH_EXT_POWER as I use SPAD.next to get LVARs. Is there is something I am missing ?
Thanks In Advance. @John Dowson