Possibly ERR_CODE
is a typedef introduced by the book author (you should check it). Tipically error codes have been historically represented using 32 bit integers, like HRESULT. You may infer the correct data type represented by ERR_CODE
by inspecting the actual return values of the implemented functions.
I am not sure how to check the return types of implemented functions, but maybe if I copied the function over to you, you could tell me. The MFC "add funtion wizard" does not allow you to make up your own typedef. There are only the usual ones (int, char, unsigned char, long, etc...)
Here is one of the functions-
ERR_CODE PortInitialize(LPTSTR lpszPortName, pSerialCreate pCreate)
{
HANDLE hPort;
DWORD dwError;
DCB PortDCB;
ERR_CODE ecStatus = OK;
COMMTIMEOUTS CommTimeouts;
unsigned char dBit;
// Open the serial port.
hPort = CreateFile(lpszPortName, // Pointer to the name of the port
GENERIC_READ | GENERIC_WRITE,
// Access (read/write) mode
0, // Share mode
NULL, // Pointer to the security attribute
OPEN_EXISTING, // How to open the serial port
0, // Port attributes
NULL); // Handle to port with attribute to copy
// If it fails to open the port, return error.
if ( hPort == INVALID_HANDLE_VALUE )
{
// Could not open the port.
dwError = GetLastError();
msg("Unable to open the port");
CloseHandle(hPort);
return EC_FOPEN;
}
PortDCB.DCBlength = sizeof(DCB);
// Get the default port setting information.
GetCommState(hPort, &PortDCB);
// Change the DCB structure settings.
PortDCB.BaudRate = pCreate->lBaudRate; // Current baud
PortDCB.fBinary = TRUE; // Binary mode; no EOF check
PortDCB.fParity = TRUE; // Enable parity checking.
PortDCB.fOutxCtsFlow = FALSE; // No CTS output flow control
PortDCB.fOutxDsrFlow = FALSE; // No DSR output flow control
PortDCB.fDtrControl = DTR_CONTROL_ENABLE; // DTR_CONTROL
// DTR flow control type
PortDCB.fDsrSensitivity = FALSE; // DSR sensitivity
PortDCB.fTXContinueOnXoff = TRUE; // XOFF continues Tx
PortDCB.fOutX = FALSE; // No XON/XOFF out flow control
PortDCB.fInX = FALSE; // No XON/XOFF in flow control
PortDCB.fErrorChar = FALSE; // Disable error replacement.
PortDCB.fNull = FALSE; // Disable null stripping.
PortDCB.fRtsControl = RTS_CONTROL_ENABLE; // RTS_CONTROL
// RTS flow control
PortDCB.fAbortOnError = FALSE; // Do not abort reads/writes on error.
dBit = (unsigned char)pCreate->lDataBits;
PortDCB.ByteSize = dBit; // Number of bits/bytes, 4-8
PortDCB.Parity = NOPARITY; // 0-4=no,odd,even,mark,space
PortDCB.StopBits = ONESTOPBIT; // 0,1,2 = 1, 1.5, 2
// Configure the port according to the specifications of the DCB structure.
if (!SetCommState (hPort, &PortDCB))
{
// Could not create the read thread.
dwError = GetLastError();
msg("Unable to configure the serial port");
return EC_INVAL_CONFIG;
}
// Retrieve the time-out parameters for all read and write operations on the port.
GetCommTimeouts(hPort, &CommTimeouts);
// Change the COMMTIMEOUTS structure settings.
CommTimeouts.ReadIntervalTimeout = MAXDWORD;
CommTimeouts.ReadTotalTimeoutMultiplier = 0;
CommTimeouts.ReadTotalTimeoutConstant = 0;
CommTimeouts.WriteTotalTimeoutMultiplier = 10;
CommTimeouts.WriteTotalTimeoutConstant = 1000;
// Set the time-out parameters for all read and write operations on the port.
if (!SetCommTimeouts (hPort, &CommTimeouts))
{
// Could not create the read thread.
dwError = GetLastError();
msg("Unable to set the time-out parameters");
return EC_TIMEOUT_SET;
}
EscapeCommFunction(hPort, SETDTR);
EscapeCommFunction(hPort, SETRTS);
pCreate->h_Port = hPort;
return ecStatus;
}
I am thinking you are right and it is probably an int that is returned. But will specifying an int type work as I add this funtion with the function wizard in VS2008?
Thank You,
[deleted]@verizon.net
Bob
Updated 24-Jun-11 12:30pm
v2