BuildCommDCBA function

Fills a specified DCB structure with values specified in a device-control string. The device-control string uses the syntax of the mode command.

Syntax

BOOL BuildCommDCBA(
  LPCSTR lpDef,
  LPDCB  lpDCB
);

Parameters

lpDef

The device-control information. The function takes this string, parses it, and then sets appropriate values in the DCB structure pointed to by lpDCB.

The string must have the same form as the mode command's command-line arguments:

COMx[:][baud=b][parity=p][data=d][stop=s][to={on|off}][xon={on|off}][odsr={on|off}][octs={on|off}][dtr={on|off|hs}][rts={on|off|hs|tg}][idsr={on|off}]

The device name is optional, but it must specify a valid device if used.

For example, the following string specifies a baud rate of 1200, no parity, 8 data bits, and 1 stop bit:

baud=1200 parity=N data=8 stop=1

lpDCB

A pointer to a DCB structure that receives the information.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The BuildCommDCB function adjusts only those members of the DCB structure that are specifically affected by the lpDef parameter, with the following exceptions:

  • If the specified baud rate is 110, the function sets the stop bits to 2 to remain compatible with the system's mode command.
  • By default, BuildCommDCB disables XON/XOFF and hardware flow control. To enable flow control, you must explicitly set the appropriate members of the DCB structure.
The BuildCommDCB function only fills in the members of the DCB structure. To apply these settings to a serial port, use the SetCommState function.

There are older and newer forms of the mode syntax. The BuildCommDCB function supports both forms. However, you cannot mix the two forms together.

The newer form of the mode syntax lets you explicitly set the values of the flow control members of the DCB structure. If you use an older form of the mode syntax, the BuildCommDCB function sets the flow control members of the DCB structure, as follows:

  • For a string that does not end with an x or a p:
    • fInX, fOutX, fOutXDsrFlow, and fOutXCtsFlow are all set to FALSE
    • fDtrControl is set to DTR_CONTROL_ENABLE
    • fRtsControl is set to RTS_CONTROL_ENABLE
  • For a string that ends with an x:
    • fInX and fOutX are both set to TRUE
    • fOutXDsrFlow and fOutXCtsFlow are both set to FALSE
    • fDtrControl is set to DTR_CONTROL_ENABLE
    • fRtsControl is set to RTS_CONTROL_ENABLE
  • For a string that ends with a p:
    • fInX and fOutX are both set to FALSE
    • fOutXDsrFlow and fOutXCtsFlow are both set to TRUE
    • fDtrControl is set to DTR_CONTROL_HANDSHAKE
    • fRtsControl is set to RTS_CONTROL_HANDSHAKE

Requirements

   
Minimum supported client Windows XP
Minimum supported server Windows Server 2003
Target Platform Windows
Header winbase.h (include Windows.h)
Library Kernel32.lib
DLL Kernel32.dll

See also

Communications Functions

Communications Resources

DCB

SetCommState