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

P3D v5 Passing strings in SimConnect

DragonflightDesign

Resource contributor
Messages
1,187
Country
northernireland
Does anyone have an example of how to use SimConnect_InsertString please? The SDK is pretty coy on it, Google doesn't have a clue and I have no idea how to work with pointers to pointers because I've never learned nor done it. At least with SimConnect_RetrieveString there's a short example of how to do it.

Thank you.

-Dai
 
What on earth would you need to use that for? While I understand the purpose of the retrieval function... this one just doesn't make any sense with regards to actual purpose. What structure are you going to "insert" the string into?
 
I think it's possibly very poorly named. I'm also pretty sure it does not do what I need i.e. to pass a string (actually a GUID) using SimConnect. Here's the P3D SDK notes:

SimConnect_InsertString​

The SimConnect_InsertString function is used to assist in adding variable length narrow strings to a structure.

Syntax​

HRESULT SimConnect_InsertString(
BYTE*
pDest,
DWORD
cbDest,
void**
ppEnd,
DWORD*
pcbStringV,
const char*
pSource
);

Parameters​

pDest [in] Pointer to where the source string is to be written in the destination
object. cbDest[in] The size of the remaining space in the destination object.
ppEnd[in,out] Pointer to a pointer, (usually a pointer to a char pointer). On return the pointer locates the end of the string in the structure, and hence the starting position for any other string to be included in the structure.
pcbStringV [in,out] Pointer to a DWORD. On returning this DWORD will contain the size of the source string in bytes.
pSource[in] Pointer to the source string.

Return Values​

The function returns an HRESULT. Possible values include, but are not limited to, those in the following table.

Return valueDescription
S_OK The function succeeded.
E_FAIL The function failed.

Remarks​

This function does not communicate with the SimConnect server [my italics], but is a helper function to assist in the handling of variable length narrow strings. Its counterpart is the SimConnect_RetrieveString function.
 
Passing a string via SimConnect is as simple as passing a pointer. The only catch to passing a pointer is if you're working in 64-bit as the pointer variable type is not 64-bit in the SimConnect declaration and thus doesn't have enough stack space to actually move a 64-bit pointer. At least, that how it was last I looked.
 
Nothing's changed Ed. I got well and truly caught out trying to pass a long long variable some time ago. It really didn't like being stuffed into a DWORD. As it is, I've come up with the crude and ugly solution of converting the GUID to a struct of eight doubles, squirting them across the network and reassembling them into the GUID at the other end. I don't like it, it's horrible, but it works.
 
Last edited:
These functions are for blocks of data where you use variable-length strings rather than fixed-length ones, so you can conserve bytes while exchanging data with the simulator.

I think you have to consider the age of the API as well as the C language. Using a block of memory where you have to insert multiple strings of varying length, each with no other indication of its length than a terminating zero byte, was something that people could get terribly confused with. The "SimConnect_InsertString" and "SimConnect_RetrieveString" methods provided replacements for boiler-plate code, allowing people to refrain from directly having to use the "strlen", "strcpy", and "strncpy" library functions of C. The unbridled use of these is at the heart of many hard-to-trace bugs and vulnerabilities that continue to plague us even now. A (modern) C++ (or any other language supporting an Object Oriented approach) API would use a vector of strings, where you "just" add another string to the vector without having to worry about how this is actually stored in memory, and where the vector is guarding data storage consistency and correctness.

So, they definitely are useful when you are exchanging data with the simulator using the tagged format (only providing data that actually changes) and therefore don't have a struct exactly mapping each individual value.
 
I agree. I meant to answer your comment some time ago but kept forgetting - mea culpa. The big problem (for me) is there is no native way of passing strings across the SimConnect network as per the SDK docs: 'This function does not communicate with the SimConnect server'. In the end I built an awful frankenstein server-client setup that passes strings as their ASCII equivalent in blocks of doubles and rebuilds them at the other end. It's horrible. I'm not proud of it. Ed would laugh me out of the country :oops: But it works for the limited length strings I need to shuffle around :)
 
Back
Top