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.
CFSUIPC();
CFSUIPC( DWORD dwFSReq );
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
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.
CFSUIPC FSConnection;
FSConnection.Open(SIM_ANY);
.
CFSUIPC FSConnection(SIM_FS2K2);
.
BOOL Open( DWORD dwFSReq );
TRUE is the function succeeded, FALSE otherwise.
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
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).
CFSUIPC FSConnection;
FSConnection.Open(SIM_ANY);
.
BOOL Read( DWORD dwOffset, DWORD dwSize, void *pDest)
TRUE is the function succeeded, FALSE otherwise.
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.
You must call the Process member function to process the read request.
DWORD FSVersion;
if (!FSConnection.Read(0x3308, 4, &FSVersion))
MessageBox(FSConnection.GetResultMessageString());
.
BOOL Write( DWORD dwOffset, DWORD dwSize, void *pSrce)
TRUE is the function succeeded, FALSE otherwise.
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.
You must call the Process member function to process the write request.
int Heat = 1;
if (!FSConnection.Write(0x029C, 2, &Heat))
MessageBox(FSConnection.GetResultMessageString());
.
TRUE is the function succeeded, FALSE otherwise.
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.
if (!FSConnection.Process())
MessageBox(FSConnection.GetResultMessageString());
.
BOOL ReadAndProcess( DWORD dwOffset, DWORD dwSize, void *pSrce)
TRUE is the function succeeded, FALSE otherwise.
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.
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.
DWORD FSVersion;
if (!FSConnection.ReadAndProcess(0x3308, 4, &FSVersion))
MessageBox(FSConnection.GetResultMessageString());
.
BOOL WriteAndProcess( DWORD dwOffset, DWORD dwSize, void *pSrce)
TRUE is the function succeeded, FALSE otherwise.
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.
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.
int Heat = 1;
if (!FSConnection.WriteAndProcess(0x029C, 2, &Heat))
MessageBox(FSConnection.GetResultMessageString());
.
The FSUIPC version number.
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.
DWORD FSUIPCVersion;
FSUIPCVersion = FSConnection.GetVersion();
.
The version of Flight Simulator currently running as determined by FSUIPC.
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
DWORD FSVersion;
FSVersion = FSConnection.GetFSVersion();
.
The last result message that a CFSUIPC member function generated.
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.
FSConnection.WriteAndProcess(0x029C, 2, &Heat)
if (FSConnection.GetResultMessage() > 0)
MessageBox(There was an error);
.
CString GetResultMessageString()
The last result message that a CFSUIPC member function generated, in a human readable format.
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.
if (!FSConnection.WriteAndProcess(0x029C, 2, &Heat))
MessageBox(FSConnection.GetResultMessageString());
.