The CreatePortEx method creates a new virtual serial port for the current user session.

BOOL CreatePortEx(

      BSTR szPortName, //  name of the virtual serial port to create or to connect to (via AttachExmethod) 

        BSTR IdUserSession // user session ID in which the virtual port is available.

 If a port is created globally, the parameter is equal to an empty string.



  • PortName: [in] Name of virtual serial port to be created. Could be any but not longer than 128 characters.
  • IdUserSession: User session ID in which the virtual port is available. If a port is created globally, the parameter is equal to an empty string.
Return Values: If the function succeeds, the return value is TRUE. If the port is already created, or no virtual serial bus is present in the system, or virtual serial port could not be created for any other reason, the return value is FALSE.

Note: Use Delete method to delete the created virtual serial port. If your program exits without calling Delete method, it will be called automatically in virtual serial port object destructor.