I don't use SimConnect at all (I've had no need for it yet)
This is not really relevant if Simconnect is used or not, it's just that Simconnect it's easier and way more flexible to use to handle timely updates (becase you can *choose* the sample ratio and you can choose to subscribe to multiple sample ratios as well, and are not forced to the 18 hz of the Gauge callback PRE_UPDATE), but even in pre-Simconnect days (in FS9), the concept of not using the Gauge callbacks, and initialize globally only in the module_init()/module_deinit() was still possible and, IMHO, desiderable. Below, an explanation will follow...
so instead I do use service_id's in the dllMain. In fact, I do all my lookups in dllMain's PRE_UPDATE case.
Sorry, but I think you are making some confusion about what is DllMain.
DLLMain is not related to Gauges and Flightsim at all: it's an (optional) part of EVERY Windows .DLL, and it's the first routine that will ever get called, as soon as a .DLL is loaded first, and it's also called again, just before the .DLL is discarded.
See the explanation of DLLMain here:
http://msdn.microsoft.com/en-us/library/ms682583(VS.85).aspx
However, as the article explains, DLLMain is not the best place to do complex stuff, because there are threading isses in the DLLEntry point so, is suggest to define ANOTHER routine, to do all your initializations.
Which is why, FS9 (and FSX) gauges, also defined the module_init() and module_deinit() function, which are safer and are the best places to put all the initialization code. Below, an explanation why this is the best approach to initalize stuff...
I have one gauge that is common to both the 2d and vc panels, and have an explicit callback to dllMain.
Ahem...if you are calling it explicitely, that's not a "callback" anymore, it's just a regular function call. The whole *point* of calling "callback" a callback function, is that you don't call it, but something else will.
In fact, in your code, you haven't done anyting different than simply using a standard regulard FS gauge callback (FSAPI CPS_gaugecall), and passing the parameters you get from the callback, to what you think is your "DllMain" with a different name (main_gaugecall), but it's not, it's just another function you defined, like any other function in a regular C program.
DllMain is a special case, it's the standard DLL entry-point for every Windows .DLL and, it's also the ONLY place where you get the handle to "yourself" (with "yourself" = the main gauge), the HANDLE hinstDLL parameter. Sometimes it might be useful to *store* this handle, in case you'll ever need to call some Windows API that needs it, and DLLMain is the place you can get it so, you can't just call any other function "DLLMain with a different name", because DLLMain is a special function.
In any case, what you are doing, is calling your own routine from inside a SUB-GAUGE Callback, which is why you need to pass the service_id, so that routine can know what was the callback status when it was called.
Ok, no doubt it *works*, but I'll now try to explain why, relying on sub-gauges to handle "global" stuff, is not the best possible approach:
Let's try for a moment to forget the PRE_UPDATE constant cycle (we'll get to that later...), and concentrate on the *initialization* (and *deinit* as well) parts:
Usually, you'll want to have a central place where you initialize all your custom stuff that needs to be setup, and that Flight sim doesn't setup for you. Some examples: Init DirectSound (load all your sound buffers, etc.), if you gauge use it, init a database, give a starting value to all your custom variables, declare all your custom L: vars, etc.
If this init routine is called whenever a PANEL_SERVICE_CONNECT_TO_WINDOW event happens (if you are doing it directly in a "real" gauge callback, or in a routine that is called by it, like in your sample, doesn't matter), you are relying on the fact the SUB-gauge is loaded, at least once.
Of course, you think you are safe, because you put the gauge both in the 2D panels and in the VC, so you can be reasonably sure it will be loaded but, suppose the user SAVES a flight while in External view and loads the airplane from that flight, your SUB-gauges are not loaded, but nothing prevents the user trying to use the airplane anyway so, for example, he might start flying that way, then finally opening one of the panels only after 10 minutes of flight, so this *might* had created strange side-effects related to the fact your initialization happened after some time the airplane was loaded.
I agree that's not a normal way to fly but, why expose yourself to the risk of those problems ? Suppose you have your 3d model that has parts that appears/disappears depending on custom L: vars, and the only place those vars are initialized correctly, it's in your C code: if the user save a flight in external view, and starts a flight from that saved flight, the model might look wrong, because the init code hasn't been called yet.
Better to be more foolproof, and the module_init() + module_deinit() gives you just that: you can be 100% SURE that module_init() WILL be called, because it's NOT depending on the fact the sub-gauge is loaded or not.
This is a Module-level function, it's always called, and it's always called ONCE, as soon as the airplane that contains a reference to this gauge (any reference, it's enough you have a single main_gauge!sub_gauge_xxx entry in your panel.cfg), even if the flight starts in an outside view, when no sub-gauges are loaded yet.
The fact that is only called *once* is not marginal: this will prevent you from calling it twice by mistake, without relying on ugly semaphore tricks, like putting a global boolean to flag that initialization has already done, which are also not very safe, since you can of course forget to *check* for that boolean.
Instead, with module_init(), you don't need to worry about any of this: you are 100% sure it WILL called, you are 100% sure it will called *immediately* after the airplane will load, you are 100% sure it will called only ONCE, without having to take any measures to prevent being called twice by mistake.
Now, since we discussed initialization, let's finally deal with the routine updates, to keep things updated, which is usually made in the PRE_UPDATE cycle.
There are two cases here:
1) you do FSX only
2) you need to be compatible with FS9
In case #1, it's clear that using Simconnect it's the easiest and more flexible choice. Inside your module_init() you init Simconnect, and subscribe to System Events.
There are several events related to constant updates, depending on the update frequency: every 4 seconds, every second, 6 times per second or every visual frame.
The good thing is, you can subscribe to multiple events, which means you will be able to group updates by their frequency ratio: stuff that is complex to calculate (like navigation calculations), do not usually need to be updated in real time so you can use a low priority, like some stuff every 1 second and something even every 4 seconds. Other things (usually those related to reacting to user input ) would need a faster update rate but not really realtime so, 6 times per second it's just right, and other things need to be as fast as possible, so the visual frame rate it's better.
Instead, using the PRE_UPDATE cycle, you are stuck with the 18 hz frequency so, you can't get updates faster than that when you need them, and you again need to rely on custom variables to handle slower updates.
And of course, the previous considerations still apply: if the user starts a flight from outside, nothing will be called until one of the panels will finally be opened.
Now, let's consider the #2 case, in that you need backward compatibility with FS9: it was still possible to handle the Update cycle entirely OUTSIDE the Gauge Callback structure, even in FS9, simply using a standard Windows Timer, with the SetTimer() function.
That way, you could define a Callback yourself (a *Windows* callback, not a gauge callback), responding on a Timer event, whose frequency could be freely specified. Again, the Timer would be defined in the module_init(), and destroyed in the module_deinit().
Incidentally, this solution is ALSO cross-platform between FS9 and FSX, because it's a Windows solution rather than a Gauge solution so, it will work in boh sims, but if you are targeting FSX only, and you use Simconnect in any case, it would probably be easier to simply use Simconnect and system events instead of timers.