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

How to tell if sim is already running

Messages
238
Country
unitedstates
Hi,

I've created a standalone MFC application. Simconnect is working well. I subscribed to "simstart" and "simstop". "simstart" fires when the environment is loaded each time. Problem is, sometimes the sim is already running when my app starts. Is there a way I can know that the sim is already running so that my app knows to to go ahead and Init and begin processing?

Tx,
Gregg
 

ddawson

Resource contributor
Messages
862
Country
canada
Request data on one of the time variables. If the value is changing, the sim is running.
Also, I think when you subscribe to events like 'simstart' you will get an immediate return with the current value.
 
Messages
238
Country
unitedstates
Request data on one of the time variables. If the value is changing, the sim is running.
Also, I think when you subscribe to events like 'simstart' you will get an immediate return with the current value.

Thanks Doug. I did subscribe to simstart and I do get a message when I click a menu item and then close the resultant dialog. If the sim was already running, however, the simstart message didn't happen when I started my app . I'll look at the time option.

SimConnect_RequestSystemState

Thanks. I'll take a look.
 
Messages
238
Country
unitedstates
SimConnect_RequestSystemState

I've been mulling this idea. After I call SimConnect_Open, I could call both of these together:
hr = SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_SIM_START, "SimStart");
hr = SimConnect_RequestSystemState(hSimConnect, EVENT_SIM_STATE, "Sim");

If the sim is already running then I'd get an immediate 0 in SIMCONNECT_RECV_ID_SYSTEM_STATE "EVENT_SIM_STATE and know to go ahead and initialize. If I got 1 (or any other value) from SIMCONNECT_RECV_ID_SYSTEM_STATE EVENT_SIM_STATE then I'd just not initialize and wait for the SIMCONNECT_RECV_ID_EVENT EVENT_SIM_START event and start my initialization then. Is that the best way?

Gregg
 

ollyau

Resource contributor
Messages
1,026
Country
us-california
The documentation says that Sim returns 1 if the user has control and 0 if the user is in the UI:

Requests the state of the simulation. If 1 is returned, the user is in control of the aircraft, if 0 is returned, the user is navigating the UI. This is the same state that notifications can be subscribed to with the "SimStart" and "SimStop" string with the SimConnect_SubscribeToSystemEvent function.

On the subject of SimStart, the SDK documentation has this to say:

The simulator is running. Typically the user is actively controlling the aircraft on the ground or in the air. However, in some cases additional pairs of SimStart/SimStop events are sent. For example, when a flight is reset the events that are sent are SimStop, SimStart, SimStop, SimStart. Also when a flight is started with the SHOW_OPENING_SCREEN value (defined in the FSX.CFG file) set to zero, then an additional SimStart/SimStop pair are sent before a second SimStart event is sent when the scenery is fully loaded. The opening screen provides the options to change aircraft, departure airport, and so on.
 
Messages
497
Country
unitedstates
Hi,

I've created a standalone MFC application. Simconnect is working well. I subscribed to "simstart" and "simstop". "simstart" fires when the environment is loaded each time. Problem is, sometimes the sim is already running when my app starts. Is there a way I can know that the sim is already running so that my app knows to to go ahead and Init and begin processing?

Tx,
Gregg

To determine if FSX is "Running", check to see if the process "fsx" exists.

ie

if (System.Diagnostics.Process.GetProcessesByName("fsx").Length == 0)
{
// FSX is NOT running
return;
}


Note: The OP is asking if FSX is running or not -- NOT asking if Simconnect is working
Geoff
 
Messages
120
Country
unitedstates
Here is how I do it in C#

System.Diagnostics.Process[] ieProcs = Process.GetProcessesByName("fsx");
if (ieProcs.Length > 0)
{
foreach (System.Diagnostics.Process p in ieProcs)
{
hWnd = p.MainWindowHandle;
// fsx is running - do stuff here
}
}
 

mgh

Messages
1,413
Country
unitedkingdom
I understand that GetProcessesByName() is only for .NET and not for C++?
 
Messages
497
Country
unitedstates
I understand that GetProcessesByName() is only for .NET and not for C++?

I think you will find that you can use still do this in C++

ie

[C++]
#using <mscorlib.dll>
#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel;

int main() {
// Get the current process.
Process* currentProcess = Process::GetCurrentProcess();

// Get all instances of Notepad running on the local
// computer.
Process* localByName[] = Process::GetProcessesByName(S"FSX");

// Get all instances of FSX running on the specific
// computer.
// 1. Using the computer alias (do not precede with "\\").
Process* remoteByName[] = Process::GetProcessesByName(S"FSX", S"myComputer");

// 2. Using an IP address to specify the machineName parameter.
Process* ipByName[] = Process::GetProcessesByName(S"FSX", S"169.0.0.0");

// Get all processes running on the local computer.
Process* localAll[] = Process::GetProcesses();

// Get all processes running on the remote computer.
Process* remoteAll[] = Process::GetProcesses(S"myComputer");

// Get a process on the local computer, using the process id.
Process* localById = Process::GetProcessById(1234);

// Get a process on a remote computer, using the process id.
Process* remoteById = Process::GetProcessById(2345, S"myComputer");
}


Ref:
https://msdn.microsoft.com/en-us/library/aa326947%28v=vs.71%29.aspx


Geoff

Note :D = : D (without space) -- cannot find option here to stop this happening !!
 
Last edited:

n4gix

Resource contributor
Messages
11,674
Country
unitedstates
Note :D = : D (without space) -- cannot find option here to stop this happening !!
Geoff, it is simple enough. Click on the "Insert" icon (just to the left of the 3 1/4" disk icon), then paste your code in the popup box.
Code:
using namespace System::Diagnostics;
Alternatively, you can simply type {code}insert code here{/code} (using square brackets [ ]instead of braces { })
 
Messages
497
Country
unitedstates
Geoff, it is simple enough. Click on the "Insert" icon (just to the left of the 3 1/4" disk icon), then paste your code in the popup box.
Code:
using namespace System::Diagnostics;
Alternatively, you can simply type {code}insert code here{/code} (using square brackets [ ]instead of braces { })

Thanks Bill (yet again)

I have lost count of the number of times you have helped me ... each time is greatly appreciated.

Geoff
 

mgh

Messages
1,413
Country
unitedkingdom
I think you will find that you can use still do this in C++

Have you tried using this and on which type of Visual C++ 2010 Express project:

CLR Console Application
CLR Empty Project
Empy Project
Win32 Console Application
Win32 Project
Windows forms Application


(I assume Class Library and Makefile Projects aren't relevant?)

I'm having problems :(
 
Messages
497
Country
unitedstates
Have you tried using this and on which type of Visual C++ 2010 Express project:

CLR Console Application
CLR Empty Project
Empy Project
Win32 Console Application
Win32 Project
Windows forms Application


(I assume Class Library and Makefile Projects aren't relevant?)

I'm having problems :(

No, I have not tried this in C++ ... only in C#

Which is why I referenced the original MSDN information source.

https://msdn.microsoft.com/en-us/library/aa326947%28v=vs.71%29.aspx
 
Top