locked
Integrate an external application RRS feed

  • Question

  • Hi,
    I have a problem, I want to develop an interface for a another application Microsoft ESP (a flight simulator).
    But I don't know how can I add ESP in a windows developped by WPF.


    Can you help me,please?

    Thanks.
    fafarun.


    • Changed type Marco Zhou Tuesday, September 23, 2008 6:06 AM off topic thread
    • Moved by Marco Zhou Tuesday, September 23, 2008 6:09 AM ESP issue indeed (Moved from Windows Presentation Foundation (WPF) to Microsoft ESP Platform Development)
    • Changed type Todd Landstad Thursday, October 9, 2008 9:49 PM more of a question than a discussion
    Thursday, September 18, 2008 1:54 PM

Answers

  • Hi Fafarun,

    If what you are asking is can ESP be loaded within a window in your WPF app, the answer is no.  ESP runs as its own app, in its own top-level window.  Extensibility is provided by the SimConnect library which allows C++ based DLL addons to be loaded within the same process as ESP.EXE and C++ or Managed EXE addons to be run out-of-proc (or even on another machine, when doing a demo with some folks from Grumman, we had 8 machines all interacting via SimConnect at the same time, a couple of those machines were also doing Multiplayer simultaneously - and the demo didn't crash when all the "bosses" showed up on demo day either :-> ).

    Hey Clark, good to see some of the rest of the dev team in here posting :->

    For a third variation on handling SimConnect message processing under WPF, check out this blog entry.  If you skip the this.Dispatcher.Invoke wrapper on the MessageProcess, then your OnRecvXxx functions will be called on a background thread.  If you can handle the few times with syncing with the UI thread is required, this can be much more efficient.  I found it was especially useful when using Data Binding with objects that support Property Changed notifications - you can update these data objects on the background thread, and the Property Changed noticfication system will sync with the UI thread at some later point and update the display.

    Tim
    http://beatlesblog.spaces.live.com/
    • Marked as answer by Todd Landstad Thursday, October 9, 2008 9:49 PM
    Wednesday, October 1, 2008 4:36 AM

All replies

  • You might ask this question at wrong forum, this is Windows Presentation Foundation forum, not ESP forum.

    Moved to ESP forum.

    Thanks
    • Edited by Marco Zhou Tuesday, September 23, 2008 6:08 AM bad typo
    Tuesday, September 23, 2008 6:06 AM
  • Hi fafarun,
     
    There are a couple ways you can hook up a WPF application to communicate with ESP.

    The first way uses the message pump and window handles similar to how you would do it with a WinForms or standard windows application.  You can start by grabbing the handle to the main WPF window by using the System.Windows.Interop.WindowInteropHelper class.  You can only grab the handle for your window after it has been created.  A good place to do this is once your main WPF window has loaded.  You can do this by registering for the System.Windows.Window.Loaded event on your main Window.  Here is code that shows how to do this:

    /// <summary>     
    /// Represents the main window of the application.     
    /// </summary>     
    public partial class MainWindow : Window     
    {     
    SimConnect m_simConnect = null;     
    static MainWindow s_this = null;     
    ...     
    private void MainWindow_Loaded(object sender, RoutedEventArgs e)        
    {        
        s_this = this;     
        
        // Set up the WndProc to listen for ESP related system events.        
        m_hwndSource = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);        
        m_hwndSource.AddHook(MainWindowWndProc);        
    }       
    ...     
    private static IntPtr MainWindowWndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)     
    {     
        if (msg == 0x0402) // WM_USER_SIMCONNECT     
        {     
            if (s_this.m_simConnect != null)  
            {  
                s_this.m_simConnect.ReceiveMessage();  
            }  
        }     
        
        return IntPtr.Zero;  
    }    
    ...  
    private void Connect()  
    {  
        m_simConnect = new SimConnect("MyApp"new WindowInteropHelper(this).Handle, 0x0402, null, 0);  
        ...  

    The other way you can do it is by using an EventWaitHandle like this:

    System.Threading.EventWaitHandle m_scReady = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset);  
    System.Threading.Thread m_thread = null;  
    SimConnect m_simConnect = null;  
    public delegate void MyDelegate();  
    ...  
    private void Connect()  
    {  
        m_simConnect = new SimConnect("MyApp", IntPtr.Zero, 0, m_scReady, 0);  
     
        m_thread = new System.Threading.Thread(new System.Threading.ThreadStart(MessageThread));  
        m_thread.IsBackground = true;  
        m_thread.Start();  
     
    }  
    ...  
    private void MessageThread()  
    {  
        while (true)  
        {  
            m_scReady.WaitOne();  
            this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new MyDelegate(MessageProcess));  
        }  
     
    }  
    ...  
    private void MessageProcess()  
    {  
        m_simConnect.ReceiveMessage();  
    }  
     

    Clark
    Monday, September 29, 2008 6:24 PM
  • Hi Fafarun,

    If what you are asking is can ESP be loaded within a window in your WPF app, the answer is no.  ESP runs as its own app, in its own top-level window.  Extensibility is provided by the SimConnect library which allows C++ based DLL addons to be loaded within the same process as ESP.EXE and C++ or Managed EXE addons to be run out-of-proc (or even on another machine, when doing a demo with some folks from Grumman, we had 8 machines all interacting via SimConnect at the same time, a couple of those machines were also doing Multiplayer simultaneously - and the demo didn't crash when all the "bosses" showed up on demo day either :-> ).

    Hey Clark, good to see some of the rest of the dev team in here posting :->

    For a third variation on handling SimConnect message processing under WPF, check out this blog entry.  If you skip the this.Dispatcher.Invoke wrapper on the MessageProcess, then your OnRecvXxx functions will be called on a background thread.  If you can handle the few times with syncing with the UI thread is required, this can be much more efficient.  I found it was especially useful when using Data Binding with objects that support Property Changed notifications - you can update these data objects on the background thread, and the Property Changed noticfication system will sync with the UI thread at some later point and update the display.

    Tim
    http://beatlesblog.spaces.live.com/
    • Marked as answer by Todd Landstad Thursday, October 9, 2008 9:49 PM
    Wednesday, October 1, 2008 4:36 AM
  • Hi,

    thanks for your explication.


    fafarun.
    Thursday, October 2, 2008 2:59 PM
  • ClarkMorse said:

    Hi fafarun,
     
    There are a couple ways you can hook up a WPF application to communicate with ESP.

    The first way uses the message pump and window handles similar to how you would do it with a WinForms or standard windows application.  You can start by grabbing the handle to the main WPF window by using the System.Windows.Interop.WindowInteropHelper class.  You can only grab the handle for your window after it has been created.  A good place to do this is once your main WPF window has loaded.  You can do this by registering for the System.Windows.Window.Loaded event on your main Window.  Here is code that shows how to do this:

    /// <summary>     
    /// Represents the main window of the application.     
    /// </summary>     
    public partial class MainWindow : Window     
    {     
    SimConnect m_simConnect = null;     
    static MainWindow s_this = null;     
    ...     
    private void MainWindow_Loaded(object sender, RoutedEventArgs e)        
    {        
        s_this = this;     
        
        // Set up the WndProc to listen for ESP related system events.        
        m_hwndSource = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);        
        m_hwndSource.AddHook(MainWindowWndProc);        
    }       
    ...     
    private static IntPtr MainWindowWndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)     
    {     
        if (msg == 0x0402) // WM_USER_SIMCONNECT     
        {     
            if (s_this.m_simConnect != null)  
            {  
                s_this.m_simConnect.ReceiveMessage();  
            }  
        }     
        
        return IntPtr.Zero;  
    }    
    ...  
    private void Connect()  
    {  
        m_simConnect = new SimConnect("MyApp"new WindowInteropHelper(this).Handle, 0x0402, null, 0);  
        ...  

    The other way you can do it is by using an EventWaitHandle like this:

    System.Threading.EventWaitHandle m_scReady = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset);  
    System.Threading.Thread m_thread = null;  
    SimConnect m_simConnect = null;  
    public delegate void MyDelegate();  
    ...  
    private void Connect()  
    {  
        m_simConnect = new SimConnect("MyApp", IntPtr.Zero, 0, m_scReady, 0);  
     
        m_thread = new System.Threading.Thread(new System.Threading.ThreadStart(MessageThread));  
        m_thread.IsBackground = true;  
        m_thread.Start();  
     
    }  
    ...  
    private void MessageThread()  
    {  
        while (true)  
        {  
            m_scReady.WaitOne();  
            this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new MyDelegate(MessageProcess));  
        }  
     
    }  
    ...  
    private void MessageProcess()  
    {  
        m_simConnect.ReceiveMessage();  
    }  
     

    Clark


    Hi,
    excuse me, but I don't understand what's happen. I try the code and nothing. Just a blank window WPF opened.

    Thanks.
    fafarun

    Friday, October 3, 2008 7:47 AM
  • The above code explains how to set up a WPF application and use SimConnect to communicate with ESP.  Beyond that, it shouldn't do anything special.  Could you explain in more detail what you are trying to achieve?  Thanks :D.

    Clark

    Wednesday, October 8, 2008 4:00 PM