January 16, 200719 yr This doesn't work. Can aynone help?using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using Microsoft.FlightSimulator.SimConnect;using System.Runtime.InteropServices;namespace SimConnectFileNameReader_T1{ public partial class Form1 : Form { SimConnect simconnect; const int WM_USER_SIMCONNECT = 0x0402; public Form1() { InitializeComponent(); } enum DEFINITIONS { Struct1, } enum DATA_REQUESTS { REQUEST_1, }; [structLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] struct Struct1 { // this is how you declare a fixed size string [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public String szFileName; public uint dwFlags; }; private void button_Connect_Click(object sender, EventArgs e) { try { simconnect = new SimConnect("SimConnectFileNameTest1", this.Handle, WM_USER_SIMCONNECT, null, 0); textbox_Connect.Text = "Connected to FSX."; simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "szFileName", null, SIMCONNECT_DATATYPE.STRING256, 0.0f, SimConnect.SIMCONNECT_UNUSED); simconnect.RegisterDataDefineStruct(DEFINITIONS.Struct1); simconnect.OnRecvEventFilename += new SimConnect.RecvEventFilenameEventHandler(simconnect_OnRecvEventFilename); } catch (COMException ex) { textbox_Connect.Text = "Error connecting to FSX."; } } void simconnect_OnRecvEventFilename(SimConnect sender, SIMCONNECT_RECV_EVENT_FILENAME data) { switch ((DATA_REQUESTS)data.uEventID) { case DATA_REQUESTS.REQUEST_1: textBox_FileName.Text = data.szFileName; break; } } protected override void DefWndProc(ref Message m) { if (m.Msg == WM_USER_SIMCONNECT) { if (simconnect != null) { simconnect.ReceiveMessage(); } } else { base.DefWndProc(ref m); } } }}Thank you very much!
January 16, 200719 yr Sorry that I saw this so late tonight, I'll take a look tomorrow morning and see what's up.
January 20, 200719 yr I might be blind or so (it's 4am) but you don't send any requests or setup any system events that you want to receive.For example you could do something like that (after connecting):simconnet.SubscribeToSystemEvent(MyEventIDEnum.FlightLoaded, "FlightLoaded")simconnet.SubscribeToSystemEvent(MyEventIDEnum.FlightSaved, "FlightSaved")simconnect.SubscribeToSystemEvent(MyEventIDEnum.AircraftLoaded, "AircraftLoaded")simconnect.SubscribeToSystemEvent(MyEventIDEnum.FlightPlanActivated, "FlightPlanActivated")This will sooner or later reward you with a bunch of filename events.
Create an account or sign in to comment