SimConnect translation help

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
MikeB
Posts: 4
Joined: Aug 09, 2021 17:49

SimConnect translation help

Post by MikeB »

Hello, I own Microsoft Flight Simulator 2020 and have translated most of the simconnect header file from the SDK, but I am unsure about a few things. I am not a beginner in C/C++ nor am I anywhere near an expert, same holds true for FreeBasic. I am hoping that someone can answer some questions and help with some of the translations. First I have some questions about some of the translations that I made, to make sure they are correct.

My first translation that I am unsure about, the C code is:

Code: Select all

#define SIMCONNECT_STRING(name, size) char name[size]
#define SIMCONNECT_GUID GUID
#define SIMCONNECT_STRINGV(name) char name[1]
#define SIMCONNECT_DATAV(name, id, count) DWORD name
#define SIMCONNECT_FIXEDTYPE_DATAV(type, name, count, cliMarshalAs, cliType) type name[1]
I've translated to:

Code: Select all

#Macro SIMCONNECT_STRING(name_s, size)
	name_s As String * size
#EndMacro

#Define SIMCONNECT_GUID GUID

#Macro SIMCONNECT_STRINGV(name_s)
	name_s As String * 1
#EndMacro

#Macro SIMCONNECT_DATAV(name_s, id, count) 
	As DWORD name_s
#EndMacro

#Macro SIMCONNECT_FIXEDTYPE_DATAV(type_t, name_s, count, cliMarshalAs, cliType)
	name_s(1) As type_t 
#EndMacro
Is this translation correct, or did I completely miss the target?

Code: Select all

#pragma pack(push, 1)

SIMCONNECT_REFSTRUCT SIMCONNECT_RECV
{
    DWORD   dwSize;         // record size
    DWORD   dwVersion;      // interface version
    DWORD   dwID;           // see SIMCONNECT_RECV_ID
};
I read about the pragma so I think the following would be a correct translation

Code: Select all

SIMCONNECT_REFSTRUCT SIMCONNECT_RECV Field = 1
	dwSize As DWORD         ' record size
	dwVersion As DWORD      ' interface version
	dwID As DWORD           ' see SIMCONNECT_RECV_ID
End Type
I used the field statement to replace the pragma statement.

Question: Several C code has structures that look like this:

Code: Select all

SIMCONNECT_ENUM_FLAGS SIMCONNECT_VOR_FLAGS;
    static const DWORD SIMCONNECT_RECV_ID_VOR_LIST_HAS_NAV_SIGNAL  = 0x00000001;
    static const DWORD SIMCONNECT_RECV_ID_VOR_LIST_HAS_LOCALIZER   = 0x00000002;
    static const DWORD SIMCONNECT_RECV_ID_VOR_LIST_HAS_GLIDE_SLOPE = 0x00000004;
    static const DWORD SIMCONNECT_RECV_ID_VOR_LIST_HAS_DME         = 0x00000008;
I translated to:

Code: Select all

#Define SIMCONNECT_ENUM_FLAGS DWORD
' SIMCONNECT_ENUM_FLAGS SIMCONNECT_VOR_FLAGS;
Type SIMCONNECT_VOR_FLAGS As SIMCONNECT_ENUM_FLAGS  ' flags for SIMCONNECT_RECV_ID_VOR_LIST 

Static AS Const DWORD SIMCONNECT_RECV_ID_VOR_LIST_HAS_NAV_SIGNAL = &h00000001 ' Has Nav signal
Static AS CONST DWORD SIMCONNECT_RECV_ID_VOR_LIST_HAS_LOCALIZER = &h00000002 ' Has localizer
Static AS CONST DWORD SIMCONNECT_RECV_ID_VOR_LIST_HAS_GLIDE_SLOPE = &h00000004 ' Has Nav signal
Static AS CONST DWORD SIMCONNECT_RECV_ID_VOR_LIST_HAS_DME = &h00000008 ' Station has DME
This compiles correctly, however the order that this code matters in FreeBasic. I have several enumerations defined, but if I include the code after those enumerations I get an error 135 stating that EXTERN or COMMON variables cannot be intialized... Why does the header compile okay if the lines are placed before the enumeration, but has an error after the enumeration?

Translation help:

Code: Select all

STATIC AS CONST DWORD SIMCONNECT_UNUSED = DWORD_MAX ' special value to indicate unused event, ID

' SIMCONNECTAPI SimConnect_AddToDataDefinition(HANDLE hSimConnect, SIMCONNECT_DATA_DEFINITION_ID DefineID, const char * DatumName, const char * UnitsName, SIMCONNECT_DATATYPE DatumType = SIMCONNECT_DATATYPE_FLOAT64, float fEpsilon = 0, DWORD DatumID = SIMCONNECT_UNUSED);
DECLARE FUNCTION SimConnect_AddToDataDefinition CDECL( _
	BYVAL hSimConnect AS HANDLE, _
	BYVAL DefineID AS SIMCONNECT_DATA_DEFINITION_ID, _
	BYVAL DatumName AS CONST ZSTRING PTR, _
	BYVAL UnitsName AS CONST ZSTRING PTR, _
	BYVAL DatumType AS SIMCONNECT_DATATYPE = SIMCONNECT_DATATYPE_FLOAT64, _
	BYVAL fEpsilon AS SINGLE = 0, _
	BYVAL DatumID AS DWORD = SIMCONNECT_UNUSED) AS SIMCONNECTAPI
Produces this error:

Code: Select all

error 272: Local symbols can't be referenced, at parameter 7 (DatumID) of SimConnect_AddToDataDefinition() in 'BYVAL DatumID AS DWORD = SIMCONNECT_UNUSED) AS SIMCONNECTAPI'
I do not understand why I am getting this error when SIMCONNECT_UNUSED is a constant DWORD variable.

In C I have this definition:

Code: Select all

#if !defined(SIMCONNECTAPI)
#define SIMCONNECTAPI extern "C" HRESULT __stdcall
#endif
I translated to:

Code: Select all

#If  NOT  DEFINED(SIMCONNECTAPI)
#Define SIMCONNECTAPI HRESULT
#EndIf 
This is a function return for most of the function prototypes.

Note that anything that says SIMCONNECT_...STRUCT has been defined as a type.
I know that this is a lot. I've spent quite a bit of time researching, and this is kind of where I am stuck.
Post Reply