Hi All,
We are posting a quick example (6 Step setup only!) on how to use the SimIn SDK to query facility data.
Save the SimIn (x32 or x64) DLL in the same path of where your project DLL will be deployed.
Step 1
Set Up the Project Preprocessor defines.
Right click on your project. Select Properties. You should see the below menu where you can navigate to Configuration Properties > C/C++ > Preprocessor. In this case we need to define SIMINDLL to tell the .h header we will be loading a DLL.
Step 2
Include the .h files, in this case the ISimInSDK.h is necessary for all the services and we are going to include the IFacilitiesService.h in this example
Then define a Global ISimInSDK *pointer, and a facilities IFacilitiesServiceV1 *pointer as well.
These two are the only ones you need to retrieve facility data.
Step 3
In you void __stdcall module_init(void) (or DLLStart or gauge init function) function, define our GetSimInSDK function typedef and define a function pointer with this type so as to load dynamically the GetSimInSDK function:
Then go ahead and use LoadLibrary and GetProcAddress so load it.
Call GetSimInSDKCall() and the result assign it to the ISimSDK pointer:
Then query the SERVICE_IFacilitiesServiceV1, and assign it to your IFacilitiesServiceV1 pointer:
In this case (and you don't need to), we are using here a function from the core service to create a callback from the sim so we can go ahead and do our calls while the sim is running. You can use your regular gauge or SimConnect callbacks to call this code.
Step 4
We are going to query facilities in the KJFK area, with the grid/rectangle function call. You can do:
This will process your query and call your callback routine to query all facilities in the the KJFK area defined in the the Lat/Lon grid: Lat 41, Lon -74, Lat 40, Lon -72.
Step 5
We are defining a callback function called facilitiesCallback, which has the following prototype:
This function will be hit async, when query is done.
Step 6
Don’t forget to release our pointer once we are done. In module_deinit(void) (or DLLStop or whatever terminate function), call sdk->Release();
Step 7
So let’s Go! Let’s do our request call and expect an Async callback to our function
Step 8
We receive the callback and loop through the results. To see what objects are retrieved refer to the SimIn SDK. All objects and the object count are retrieved in the FacilityData* data object - you will need to loop through them to get all the data. After processing all data call facilities->ReleaseFacilityData(&data); to free all data.
The source code for this example is available here
Thanks
We are posting a quick example (6 Step setup only!) on how to use the SimIn SDK to query facility data.
Save the SimIn (x32 or x64) DLL in the same path of where your project DLL will be deployed.
Step 1
Set Up the Project Preprocessor defines.
Right click on your project. Select Properties. You should see the below menu where you can navigate to Configuration Properties > C/C++ > Preprocessor. In this case we need to define SIMINDLL to tell the .h header we will be loading a DLL.
Step 2
Include the .h files, in this case the ISimInSDK.h is necessary for all the services and we are going to include the IFacilitiesService.h in this example
Then define a Global ISimInSDK *pointer, and a facilities IFacilitiesServiceV1 *pointer as well.
These two are the only ones you need to retrieve facility data.
Step 3
In you void __stdcall module_init(void) (or DLLStart or gauge init function) function, define our GetSimInSDK function typedef and define a function pointer with this type so as to load dynamically the GetSimInSDK function:
C:
typedef SIMINCALL SIMINSDKHANDLE(WINAPI *GetSimInSDKPtr)(VOID);
GetSimInSDKPtr GetSimInSDKCall;
Then go ahead and use LoadLibrary and GetProcAddress so load it.
Call GetSimInSDKCall() and the result assign it to the ISimSDK pointer:
C:
sdk = GetSimInSDKCall();
Then query the SERVICE_IFacilitiesServiceV1, and assign it to your IFacilitiesServiceV1 pointer:
C:
sdk->GetService(SERVICE_IFacilitiesServiceV1, reinterpret_cast<void**>(&facilities));
In this case (and you don't need to), we are using here a function from the core service to create a callback from the sim so we can go ahead and do our calls while the sim is running. You can use your regular gauge or SimConnect callbacks to call this code.
Step 4
We are going to query facilities in the KJFK area, with the grid/rectangle function call. You can do:
C:
facilities->QueryFacilitiesRectangleAsync(41, -74, 40, -72, &facilitiesCallback);
This will process your query and call your callback routine to query all facilities in the the KJFK area defined in the the Lat/Lon grid: Lat 41, Lon -74, Lat 40, Lon -72.
Step 5
We are defining a callback function called facilitiesCallback, which has the following prototype:
C:
HRESULT SIMINAPI facilitiesCallback(FacilityData* data)
This function will be hit async, when query is done.
Step 6
Don’t forget to release our pointer once we are done. In module_deinit(void) (or DLLStop or whatever terminate function), call sdk->Release();
Step 7
So let’s Go! Let’s do our request call and expect an Async callback to our function
Step 8
We receive the callback and loop through the results. To see what objects are retrieved refer to the SimIn SDK. All objects and the object count are retrieved in the FacilityData* data object - you will need to loop through them to get all the data. After processing all data call facilities->ReleaseFacilityData(&data); to free all data.
The source code for this example is available here
Thanks