CFSUIPC MFC Class Version 1.0

 

Description

 

Construction

            CFSUIPC

            Open

 

Input / Output

            Read

            Write

            Process

            ReadAndProcess

            WriteAndProcess

            GetVersion

            GetFSVersion

 

Error Handling

            GetResultMessage

            GetResultMessageString


 

Description

            This Microsoft Foundation Class (MFC) code is something I build one night to allow me to access FSUIPC easier within a MFC application.  Most of this code was just ported from the existing C SDK to MFC, while other member functions were added to simplify the operation.  We will try to keep the class updated with future version of Peters FSUIPC and SDK.  Hopefully this will save some of you time when building a MFC application.  Happy coding.

Construction

          CFSUIPC

                        CFSUIPC();

                        CFSUIPC( DWORD dwFSReq );

                       

                    Parameters

                        dwFSReq

                                    Specifies what Flight Simulator you want to connect to:

·        SIM_ANY            Any simulator supported by FSUIPC

·        SIM_FS98            Microsoft Flight Simulator 98

·        SIM_FS2K            Microsoft Flight Simulator 2000

·        SIM_FS2K2            Microsoft Flight Simulator 2002

·        SIM_CFS1            Microsoft Combat Flight Simulator

·        SIM_CFS2            Microsoft Combat Flight Simulator 2

·        SIM_FLY            Refer to the FSUIPC documentation

                    Remarks

The default constructor does not open the link with FSUIPC.  Because of this, you will need to call the Open member function to create the link.

 

The constructor with one argument creates a CFSUIPC object and open the link to the FSUIPC module.  This constructor combines the function of the first (default) constructor and the Open member function.

 

When the CFSUIPC object is destroyed the connection to FSUIPC will be closed.

                    Example 1

…

CFSUIPC FSConnection;

FSConnection.Open(SIM_ANY);

….

                    Example 2

…

CFSUIPC FSConnection(SIM_FS2K2);

….

          Open

                        BOOL Open( DWORD dwFSReq );

                       

                    Return Value

                        TRUE is the function succeeded, FALSE otherwise.

                    Parameters

                        dwFSReq

Specifies what Flight Simulator you want to connect to:

·        SIM_ANY            Any simulator supported by FSUIPC

·        SIM_FS98            Microsoft Flight Simulator 98

·        SIM_FS2K            Microsoft Flight Simulator 2000

·        SIM_FS2K2            Microsoft Flight Simulator 2002

·        SIM_CFS1            Microsoft Combat Flight Simulator

·        SIM_CFS2            Microsoft Combat Flight Simulator 2

·        SIM_FLY            Refer to the FSUIPC documentation

                    Remarks

You only need to use the Open member function when you have constructed a CFSUIPC object using the default construct.

If Open returns "FALSE" then the value in the result DWORD will tell you what went wrong.  The errors currently possible are defined in the header file (see the list of FSUIPC_ERR_ ... definitions).

                    Example

                                    …

                                    CFSUIPC FSConnection;

                                    FSConnection.Open(SIM_ANY);

                                    ….

Input / Output

          Read

                        BOOL Read( DWORD dwOffset, DWORD dwSize, void *pDest)

                    Return Value

                        TRUE is the function succeeded, FALSE otherwise.

                    Parameters

                        dwOffset

                                    The offset to be read.

                        dwSize

                                    The size of the data (in bytes) to be read

                        pDest

A pointer to a variable that will hold the results of the read request.  This is defined as a void * so that you can use whatever component size or structure you like.                       

                    Remarks

You must call the Process member function to process the read request.

                    Example

                                    …

                                    DWORD FSVersion;

                                    if (!FSConnection.Read(0x3308, 4, &FSVersion))

                                                MessageBox(FSConnection.GetResultMessageString());

                                    ….

          Write

                        BOOL Write( DWORD dwOffset, DWORD dwSize, void *pSrce)

                    Return Value

                        TRUE is the function succeeded, FALSE otherwise.

                    Parameters

                        dwOffset

                                    The offset to be written to.

                        dwSize

                                    The size of the data (in bytes) that is being written.

                        pSrce

A pointer to a variable that will holds the data that will be written.  This is defined as a void * so that you can use whatever component size or structure you like.                       

                    Remarks

You must call the Process member function to process the write request.

                    Example

                                    …

                                    int Heat = 1;

                                    if (!FSConnection.Write(0x029C, 2, &Heat))

                                                MessageBox(FSConnection.GetResultMessageString());

                                    ….

          Process

                        BOOL Process( )

                    Return Value

                        TRUE is the function succeeded, FALSE otherwise.

                    Remarks

Processes all entries (read or write) that have been added since the last process.  Note that, if your program is run under WideClient, it is likely that your first requests for data are met with zeroes for everything. This is because WideClient sends off the request but meanwhile returns what it already has. If you depend on seeing correct data from the outset, you will need to wait some milliseconds (100 or more is good, 500 safer) and read again.

 

                    Example

                                    …

                                    if (!FSConnection.Process())

                                                MessageBox(FSConnection.GetResultMessageString());

                                    ….

          ReadAndProcess

BOOL ReadAndProcess( DWORD dwOffset, DWORD dwSize, void *pSrce)                       

                    Return Value

                        TRUE is the function succeeded, FALSE otherwise.

                    Parameters

                        dwOffset

                                    The offset to be read.

                        dwSize

                                    The size of the data (in bytes) to be read

                        pDest

A pointer to a variable that will hold the results of the read request.  This is defined as a void * so that you can use whatever component size or structure you like.                       

                    Remarks

This member function adds the read request and then processes it.  By using this member function there is no need to call the process member function separately.  Note that, if your program is run under WideClient, it is likely that your first requests for data are met with zeroes for everything. This is because WideClient sends off the request but meanwhile returns what it already has. If you depend on seeing correct data from the outset, you will need to wait some milliseconds (100 or more is good, 500 safer) and read again.

 

                    Example

                                    …

                                    DWORD FSVersion;

                                    if (!FSConnection.ReadAndProcess(0x3308, 4, &FSVersion))

                                                MessageBox(FSConnection.GetResultMessageString());

                                    ….

          WriteAndProcess

BOOL WriteAndProcess( DWORD dwOffset, DWORD dwSize, void *pSrce)

                    Return Value

                        TRUE is the function succeeded, FALSE otherwise.

                    Parameters

                        dwOffset

                                    The offset to be written to.

                        dwSize

                                    The size of the data (in bytes) that is being written.

                        pSrce

A pointer to a variable that will holds the data that will be written.  This is defined as a void * so that you can use whatever component size or structure you like.                       

                    Remarks

This member function adds the write request and then processes it.  By using this member function there is no need to call the process member function separately.  Note that, if your program is run under WideClient, it is likely that your first requests for data are met with zeroes for everything. This is because WideClient sends off the request but meanwhile returns what it already has. If you depend on seeing correct data from the outset, you will need to wait some milliseconds (100 or more is good, 500 safer) and read again.

 

                    Example

                                    …

                                    int Heat = 1;

                                    if (!FSConnection.WriteAndProcess(0x029C, 2, &Heat))

                                                MessageBox(FSConnection.GetResultMessageString());

                                    ….

          GetVersion

                        DWORD GetVersion()

                    Return Value

                        The FSUIPC version number.

                    Remarks

Calling this member function will return the version of the FSUIPC.DLL currently in use.  HIWORD contains the main version number as BCD x 1000: e.g. 0x1998 for 1.998.  LOWORD contains the Interim build letter as a number from 0 thru 26 representing none, a-x: e.g. 0x0005 = ‘e’.

                    Example

                                    …

                                    DWORD FSUIPCVersion;

                                    FSUIPCVersion = FSConnection.GetVersion();

                                    ….

          GetFSVersion

                        DWORD GetFSVersion()

                    Return Value

                        The version of Flight Simulator currently running as determined by FSUIPC.

                    Remarks

Possible return values are:

1.      Microsoft Flight Simulator 98

2.      Microsoft Flight Simulator 2000

3.      Microsoft Combat Flight Simulator 2

4.      Microsoft Combat Flight Simulator

5.      FLY

6.      Microsoft Flight Simulator 2002

                    Example

                                    …

                                    DWORD FSVersion;

                                    FSVersion = FSConnection.GetFSVersion();

                                    ….

Error Handling

          GetResultMessage

DWORD GetResultMessage()

                    Return Value

                        The last result message that a CFSUIPC member function generated.

                    Remarks

This result could be a success message or a failure message.  Typically if a member function returns a FALSE you would want to check the error message by calling the GetResultMessage function.

                    Example

                                    …

                                    FSConnection.WriteAndProcess(0x029C, 2, &Heat)

                                    if (FSConnection.GetResultMessage() > 0)

                                                MessageBox(“There was an error”);

                                    ….

          GetResultMessageString

CString GetResultMessageString()

                    Return Value

The last result message that a CFSUIPC member function generated, in a human readable format.

                    Remarks

This result could be a success message or a failure message.  If a member function returns a FALSE you might want to display the error message.

                    Example

                                    …

                                    if (!FSConnection.WriteAndProcess(0x029C, 2, &Heat))

                                                MessageBox(FSConnection.GetResultMessageString());

                                    ….