• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

DefWndProc question

Messages
8
Country
us-ohio
(This is C# btw)

I have a subclass that handles UDP operations from an external SimuLink application, but I don't want this subclass to be a form. Just something that opens another SimConnect connection to transmit/set information.

As I understand it, DefWndProc is a method of Forms, so how do I register this connection to receive messages?

I get an exception ('no suitable method to override') because this is not a Form.

Code:
        protected override void DefWndProc(ref Message m)
        {
            if (m.Msg == WM_USER_SIMCONNECT)
            {
                if (simConnectRecv != null)
                {
                    simConnectRecv.ReceiveMessage();
                }
            }
            else
            {
                base.DefWndProc(ref m);
            }
        }


Do I not need this then if this is running as essentially a console application? I'm slightly confused.
 
Also, when I try to initialize my new SimConnect client

Code:
simConnectRecv = new SimConnect("SimConnect - UDP Recv.Update", this.Handle, WM_USER_SIMCONNECT, null, 0);

I get an exception because, again, its not a Form, so I dont have a Window Handle.

How do I set this up?
 
Hello,
couple of possible ways, depending on what you are doing.

1) If you use the managed simconnect wrapper, the message pump is done for you internally so there is no need as far sa I know.

2) NativeWindow will allow you to subclass a regular system.windows.form and give you a handle to it in the form of an IntPtr if you need one in .NET.

3) If you use WPF, there's yet another conversion class, the name escapes me at the moment, but same deal - you can subclass a native window.

Hope this helps.

Etienne
 
No need to go through quite all of that. You just need to use the event handle mechanism provided. See this blog entry for info on how to use this (the blog entry is about WPF mostly, but the same concepts will work with a console app as well (or in your case, an non-UI based class object)).

I may have a better solution available in a couple of months (I've been working on a replacement managed client library that doesn't rely on the existing native library, its 100% managed code, and supports several .Net-isms to make life easier), but until then, the above should get you going.

Tim
 
Back
Top