Function Overloads

Hey All,

In the C++ native client’s documentation, some of the function descriptions list default values for some of the function parameters.  In C++, this means you can use a shortened form of the API function and the default values will be used.  While .Net/C# doesn’t currently support default parameter values, it does support function overloading, and I have used that ability in the new Managed SimConnect Client library to provide overloaded functional equivalents for the C++ shortened forms (I’ve used the same default values as listed in the C++ docs, so you can reference those for API specific defaults).  So when working in Visual Studio, pay attention to the IntelliSense popups, as they will list all the available overloaded versions.

I’ve also added a few “specialized” extra functions for dealing directly with the User Sim Object (basically, these functions don’t take a dwObjectID value, they internally use the constant that specifies you want to talk to the user):

RequestDataOnUserSimObject

SetDataOnUserSimObject

SendClientEventToUser

The parameter list for these APIs is equivalent to their non-User specific versions, except the dwObjectID param isn’t included in the list.

Another variety of overload I’ve used is to accept different types of data to the same API call.  The Text function uses this ability to provide a version of the function that takes a regular string (same as the C++ version) and also a version of the function that takes an array of strings (this version useful with the SIMCONNECT_TEXT_TYPE.MENU flag so you don’t have to embed nul chars(‘’) in your string.

 

A couple of samples

The MapInputEventToClientEvent function is a good example.  It’s full blown version contains 7 function parameters, but the function is valid with as little as the first 3 parameters defined.  In the original managed wrapper, you would always need to enter all 7 parameters like this:

sc.MapInputEventToClientEvent(Groups.GroupID, “shift+a”, Events.ShiftA, 0, SIMCONNECT_UNUSED, 0, false);

but with the new client library, you can use the shortened form:

sc.MapInputEventToClientEvent(Groups.GroupID, “shift+a”, Events.ShiftA);

 

The Text function can be used to display both scrolling/paging text across the top of the FSX/ESP display and to display a 1 up to 10 selection dialog.  With the original managed wrapper, you would have to define the string for a selection dialog something like this:

string strSelectionDlg1 = “Dialog TitleSelection Prompt:Selection 1Selection2Selection3”;

but with the new client library having an overload that takes a string array, you can define that same selection dialog this way:

string[] strSelectionDlg1 = { “Dialog Title”,
                              “Selection Prompt:”,
                              “Selection 1”,
                              “Selection 2”,
                              “Selection 3”};

which is much easier to read.

 

Stay tuned for more

If you notice any overloads missing or just want to suggest some additional overloads, drop a line in the SimConnect forum on FSDeveloper.com.  And keep an eye here on the blog for additional info on the new Managed Client Library.

 

Tim “Beatle” Gregson

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s