September 11, 201510 yr The FLIGHT_LOADED event is happening before you ever get to PANEL_SERVICE_PRE_UPDATE to initiate your connection to SimConnect.
September 11, 201510 yr Author Commercial Member This gets more complex... :Big Grin: Ed: thank you for confirming what I'd suspected was the underlying problem. And no, I didn't think you were being facetious. I just don't yet have the SimConnect modus operandi successfully nailed in my head. Doug: where do you suggest that I trap 'early' events like this? [Edit] Doug: just as I posted I think I figured it out. I won't be able to try until tomorrow morning, so I'd like to see if I've got it right first.
September 12, 201510 yr Author Commercial Member I really thought I'd got it this time with Ed's hint about event driven. case PANEL_SERVICE_PRE_UPDATE: if ((strlen(prevFlight) < 3) || strcmp(prevFlight,CURRENT_FLIGHT)!=0) { hr = SimConnect_RequestSystemState(hSimConnect, SIMCONNECT_RECV_ID_EVENT_FILENAME, "FlightLoaded"); SimConnect_CallDispatch(hSimConnect, SimConnectProcess, NULL); if (strlen(CURRENT_FLIGHT) > 3) strncpy(prevFlight, CURRENT_FLIGHT, sizeof(CURRENT_FLIGHT)); } break; _CallDispatch still isn't being called but the RequestSystemState is definately going out. I went on and did some further coding/checking and found I could easily trap FlightSaved: static enum EVENT_FILENAME { FLIGHT_LOADED, FLIGHT_SAVED, }; void OnRecvOpen (SIMCONNECT_RECV_OPEN *pOpen, DWORD cbData) { SimConnect_SubscribeToSystemEvent(hSimConnect, FLIGHT_LOADED, "FlightLoaded"); SimConnect_SubscribeToSystemEvent(hSimConnect, FLIGHT_SAVED, "FlightSaved"); } void OnRecvEventFilename(SIMCONNECT_RECV_EVENT_FILENAME *pData, DWORD cbData) { if (FLIGHT_SAVED)strncpy(SAVED_FLIGHT,pData->szFileName,sizeof(pData->szFileName)); if (FLIGHT_LOADED)strncpy(CURRENT_FLIGHT, pData->szFileName, sizeof(pData->szFileName)); } What am I not calling correctly for FlightLoaded? And with apologies, because I'm right at the end of my tether with frustration, may I ask if someone would be kind enough to provide some code? I obviously can't take hints.
September 13, 201510 yr Dai, Call SimConnect_CallDispatch once, as soon as you call SimConnect_Open. When you are running in process (a gauge or module) you do not have to continually call it.
September 13, 201510 yr Author Commercial Member That's what I was doing when I found that I could successfully read FlightSaved - the above code was my last despairing try before I went to bed last night. Now I'm seriously beginning to wonder if FlightLoaded actually works.
September 13, 201510 yr Sorry, I just noticed this. I think you want void OnRecvEventFilename(SIMCONNECT_RECV_EVENT_FILENAME *pData, DWORD cbData){ if (pData->uEventID == FLIGHT_SAVED)strncpy(SAVED_FLIGHT,pData->szFileName,sizeof(pData->szFileName)); if (pData->uEventID == FLIGHT_LOADED)strncpy(CURRENT_FLIGHT, pData->szFileName, sizeof(pData->szFileName));}
September 13, 201510 yr I did some testing myself. I'm now pretty certain that the "FlightLoaded" event occurs before gauges start getting loaded, so we'll never trap it in a gauge. If you need to know the current flight name, use the SimConnect_RequestSystemState function.
September 13, 201510 yr Author Commercial Member Thanks Doug - I was starting to think I was being particularly stupid. If I don't get it tonight, it will have to wait until I get back from Florida in ten days' time.
September 13, 201510 yr Author Commercial Member AT LAST!!! That has been one steep learning curve - ! It was like someone turned a (dim) light on sometime over the last two days and I'm now starting to understand the SDK. Thank you both very much for your help
Create an account or sign in to comment