In my last blog post, I mentioned we had a new download area with some new samples and that I had a couple of samples that needed some minor cleaning up and then they would be posted there. Well one of those has been posted there, the In-Process DLL SimConnect Client sample (actually, it was posted almost 2 months ago, I’m just now getting around to blogging about it :-> ).
I wrote this sample because I noticed we didn’t have any in-proc DLL samples in the SDK.
First off, what does that mean, In-Process? It means that the DLL SimConnect client is loaded within the ESP/FSX process space instead of within its own process space like an external .EXE based SimConnect client. This has some good points and some bad points (depending on what you are trying to do).
The good points are that you register a callback function once, right after the SimConnect_Open call, and that callback will get called directly by the Server Side SimConnect code when messages are available for your client. This bypasses all of the networking layer (ie no TCP/IP, no Named Pipes, you get a direct function call into your code from the Sim side code). This also means you don’t have to run your own HWND based message pump, you don’t need to use a background thread with an Event Handle, you don’t need to use a timer based query scheme, etc – in other words, it makes life much easier.
The bad points are that you can’t really do standard windows based UI this way – well, you can but its not guaranteed to work (DirectX and GDI get into fights with each other sometimes, especially in full screen mode) unless you put the Sim into Dialog Mode first. You can still add menu items, use the SimConnect_Text function to display both scrolling text and simple "select one of the below" style dialog boxes. Another bad point, in some folks eyes anyway, is you can only use C++ to write an In-Proc DLL client. Also, since your client is running within the ESP/FSX process space, if your client code goes nuts (causes a fault of some sort, or goes into an infinite loop) you can take down the entire Sim.
So, if you want to write a client with lots of UI and/or you want to use managed code, stick with an out-of-proc EXE style client, but if you can live within the above restrictions, then an in-proc DLL style client may be the way to go.
Things that would make a good in-proc DLL style client:
- adding Custom Action support for missions
- transferring data between the Sim and some external app
- interfacing custom hardware to the Sim
What the sample does
The sample is fairly simple in what it does. It adds a couple of menu items to the AddOn menu (Show Weather Menu and Show Time Menu). Selecting one of these menu items will use SimConnect_Text to show a "Select on of these options" dialogs, the weather dialog allows you to query the dialog from either the current location or from SeaTac, the time dialog lets you set the time to either 12:00 Local or 00:00 Zulu. Selecting one of the weather reporting options will query for the Metar string at the requested location, and then use SimConnect_Text to display the Metar string as a scrolling message across the top of the screen. Selecting one of the time set options will, surprisingly enough, set the time accordingly :->
Hopefully a few of you will find the sample useful. If you do, or you have any questions about it, drop by the Microsoft ESP Forum to discuss it/ask questions.
Tim "Beatle" Gregson