• 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.

Help needed with TransmitClientEvent

Messages
20
Country
france
Good day all,
I am encountering a difficulty with TransmitClientEvent in VB.Net. I want to set the value for the elevator trim. The SDK says value = -16383 to +16383 for "AXIS_ELEV_TRIM_SET".

All works well while the value I want to send is positive. As soon as it becomes negative, I get an overflow exception. Many controls having a range between -16383 to + 16383, it is very annoying.

I try to pass the value as an Int16, am I missing something?

Thanks by advance for any help

Best regards,

Robert
 
I try to pass the value as an Int16, am I missing something?

Yes. Why did you "choose" Int16? It must be a (normal) Int32. A negative 16-bit number will be > 32767 which is out of the accepted range -16384 to +16384.

Always check protoypes when sizing parameters. The SimConnect documentation itself defines TransmitClientEvent as:

HRESULT SimConnect_TransmitClientEvent(
HANDLE hSimConnect,
SIMCONNECT_OBJECT_ID ObjectID,
SIMCONNECT_CLIENT_EVENT_ID EventID,
DWORD dwData,
SIMCONNECT_NOTIFICATION_GROUP_ID GroupID,
SIMCONNECT_EVENT_FLAG Flags
);

DWORD is 32-bit. Admittedly it is unsigned, but it will be cast as signed on arrival if such is needed. If you place a negative 16-bit value in a 32-bit unsigned DWORD it simply looks like a larger positive integer, 32678 - 65535.

Pete

P.S. FS is still a 32-bit application even in these days of 64-bit processors, but it is a long time since it was 16 bit. Almost all parameters and values are 32-bit integer or 64-bit float. ;-)
 
Thank you very much for your help Peter.
Indeed you were right with the dword value ! Very stupid of my own...!

However, I still get an overflow error with the transmitClientEvent. I declared a variable V as Int32 and use it to pass the value to transmitClientEvent. The program compile OK, runs fine while V is 0 or positive, and abort with an overflow in the transmitClientEvent when V is less than zero...
I tried to put the value directly in the code of the function call. I got an error at compile time "Uinteger cannot be negative"...

Regards,

Robert
 
However, I still get an overflow error with the transmitClientEvent.

Is it actually in your program, or in SimConnect, or maybe in some wrapper you are using? Have you a debugger? You should be able to pin-point it exactly.

I tried to put the value directly in the code of the function call. I got an error at compile time "Uinteger cannot be negative"...

With C or C++ you would have to cast it to unsigned or DWORD, simply prefixing it by (DWORD). I'm afraid I have no idea what you do in VB. I've always thought of it as an incomprehensibly vague language, and with .net having it managed, like through an interpreter, makes it more so to me. Sorry.

Someone who knows VB will need to step in here.

Regards

Pete
 
Thanks Peter,
perhaps with the help of the explanations you gave, it will be clear for someone with knowledge of VB.Net.
I cannot understand why the function is built with an Unsigned parameter, as most of the controls have value between -16383 an +16383, but it is true that I am not very experienced with the .Net languages...

Thanks once more,

Regards,

Robert
 
I cannot understand why the function is built with an Unsigned parameter, as most of the controls have value between -16383 an +16383

Well there are lot which don't have such a range too.

I think these parameters are derived from how the events (which I've always called "controls" because they are catalogued in the CONTROLS.DLL) have always been transmitted inside FS -- by a WM_COMMAND message with the ID number as the WPARAM and the parameter as the LPARAM parts of the Windows Message, thus:

SendMessage(hwndFS98MAIN, WM_COMMAND, (WPARAM) dwControl, (LPARAM) dwParameter);

Whilst originally WPARAM was an unsigned 16-bit (in Windows 3 days), they have both long been 32-bit unsigned values -- pointers, in fact, although not often used as such, hence almost always cast (in C). Here's how they are defined for C:

typedef UINT_PTR WPARAM;
typedef LONG_PTR LPARAM;

I don't know how the VB interface for SimConnect has been devised. The SimConnect interface itself is, of course, defined in C/C++, which is FS's own language.

Regards

Pete
 
Well there are lot which don't have such a range too.

I agree with you, but in France we often say who can the most can the less... (I hope I translate quite well...).

I hope that there is something that I miss. Unless if .net is not the native language of FS(X),I think it will become... And there is not really a difference between C# and VB.net... just a matter of syntax. And I hope that, with all your explanations (thanks once more...) somebody with good knowledge of .net will point me on the right direction... I can't believe that it is a bug in the managed version... So, if someone who knows about VB.net is reading us, help...!

Thanks Peters...

Regards,

Robert
 
My Vote

pdgnr,

Stop Struggling with C++ <-- Dead language.

Your Programming in .Net...So? Use C# (only 'C' and 'C#' and 'Assembler' are really usable languages)

Besides, A C++ guy like me? Easily slid into C#.

This is all really easy, but if we got to reach behind our backs and remember ancient code...Even Peter is gonna be stressed ;)

Show me yer code and I'll translate it for you :)

PLUS! I have already posted source for examples such as you need...search 'FlapsOut'?

I be very happy to send you more examples! :)

And the: "who can the most can the less"?!? I don't understand! LOL

Also! Re-Reading the post above that you made? PDGNR! You have not run FSInterrogate!!! (Comes with FSUIPC) Use it...Love it...Become ONE with it! Your understanding of the OverFlow would have been IMMEDIATE!

Peter? You know this as well as I...Why didn't you point the young man in the right direction :O

Ahh...You have to do speed reading with all the E-Mail you receive? I get it... ;)

Flaps

flapsout@innergears.com
 
Last edited:
Hi Flaps,
thanks for your help.
Here is the code with problem:

Code:
FSX_Simconnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, TrimEvents.TrimSet, Position, PriorityGroup.SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY)

In the SDK, it is said that Position must be in the range -16383 +16383. In fact I got an overflow as soon as Position is less than 0. It seems that in the prototype, position is declared Uinteger.

Thanks by advance,

Robert
 
Hey Robert...

Too little for me to go on...

I KNOW your a C++ programmer, so I KNOW you can send me the whole source and it will be professional.

Don't post it here but send it to :
FlapsOut@innergears.com

It's late here in Houston, Texas, USA, but I will look at it 1st thing tomorrow?

And I will reply with some equal source in C#?

PLEASE in Programmer terms? Tell me EXACTLY what you want to accompish?

After this message? Our communication will be Private :)

Thanks, Robert
 
Last edited:
Back
Top