OpenCommPort function (winbase.h)

Attempts to open a communication device.

Syntax

HANDLE OpenCommPort(
  [in] ULONG uPortNumber,
  [in] DWORD dwDesiredAccess,
  [in] DWORD dwFlagsAndAttributes
);

Parameters

[in] uPortNumber

A one-based port number for the communication device to open.

[in] dwDesiredAccess

The requested access to the device.

For more information about requested access, see CreateFile and Creating and Opening Files.

[in] dwFlagsAndAttributes

The requested flags and attributes to the device.

Note  

For this function, only values of FILE_FLAG_OVERLAPPED or 0x0 are expected for this parameter.

 
Value Meaning
FILE_FLAG_OVERLAPPED
0x40000000
The file or device is being opened or created for asynchronous I/O.

Return value

If the function succeeds, the function returns a valid HANDLE. Use CloseHandle to close that handle.

If an error occurs, the function returns INVALID_HANDLE_VALUE.

Remarks

The uPortNumber parameter accepts one-based values. A value of 1 for uPortNumber causes this function to attempt to open COM1.

To support UWP, link against WindowsApp.lib.

Requirements

Requirement Value
Minimum supported client Windows 10, version 1709 [desktop apps | UWP apps]
Minimum supported server Windows Server, version 1709 [desktop apps | UWP apps]
Target Platform Windows
Header winbase.h (include Windows.h)
Library OneCore.lib
DLL KernelBase.dll

See also

CloseHandle

CreateFile

Creating and Opening Files