Jump to content

SimConnect_Open for each command


Guest YokeM

Recommended Posts

Guest YokeM

Hey everyone,

 

I´m quite new to add-on programming and there is something I was wondering while using the SimConnect SDK. In the examples provided by Lockhead Martin there allways is a SimConnect_Open to open an instance for communication to Prepar3D. This is followed by the command that should be done in Prepar3D. After that follows a SimConnect_Close which to my understanding ends (deletes?) the communication instance.

 

My question is: Why do that? Why not simply open one instance via SimConnect_Open and use it over and over again for multiple commands, closing it only when the add-on component is closed?

Link to comment
Share on other sites

You probably want to visit a developer forum to have accesses to more expertise.

The process you are detailing is not an usual one for communication through internet and database ports.

 

-Pv-

2 carrot salad, 10.41 liter bucket, electric doorbell, 17 inch fan, 12X14, 85 Dbm
Link to comment
Share on other sites

Example opens Simconnect until it's eventually closed by Simconnect_Close()

 

HRESULT hr;
HANDLE hSimConnect = NULL;

hr = SimConnect_Open(&hSimConnect, "Your Application Name", NULL, 0, 0, SIMCONNECT_OPEN_CONFIGINDEX_LOCAL);

 

It's alway helpful to read the SDK too!

 

Remarks

 

Most client applications will have one SimConnect_Open call, and one corresponding SimConnect_Close call. However in some applications, multiplayer in particular, multiple SimConnect_Open calls may be necessary, in which case an array or list of handles will need to be maintained, and closed appropriately.

Link to comment
Share on other sites

Hey everyone,

 

I´m quite new to add-on programming and there is something I was wondering while using the SimConnect SDK. In the examples provided by Lockhead Martin there allways is a SimConnect_Open to open an instance for communication to Prepar3D. This is followed by the command that should be done in Prepar3D. After that follows a SimConnect_Close which to my understanding ends (deletes?) the communication instance.

 

My question is: Why do that? Why not simply open one instance via SimConnect_Open and use it over and over again for multiple commands, closing it only when the add-on component is closed?

 

 

It's just there for completeness. But your program does have to make the call to delete the resource since tcp connections take awhile to clean themselves up. In fact you may want to wrap the connection inside of another class, and that way if a command fails it can refresh the connection by closing it and reopening it, and if that fails reporting an error. Especially useful if you are making a remote connection.

Link to comment
Share on other sites

The SDK states:

 

Remarks

 

When a SimConnect client is closed, the server will remove all objects, menu items, group definitions and so on, defined or requested by that client, so there is no need to remove them explicitly in the client code.

 

If SimConnect is exited without calling SimConnect_Close() there is no guarantee that all its application's objects, menu items, group definitions and so on will be removed.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...