Jump to content
Sign in to follow this  
Guest jkoifman

C# Reading FileName from SimConnect

Recommended Posts

Guest jkoifman

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!

Share this post


Link to post
Share on other sites
Guest DocMoriarty

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...