How can I control on device by RS232 using CPP code

Jan Axelson's book, Serial Port Complete is a serious hardware reference for designing serial ports. First edition has some Visual Basic code. 2nd edition expands to USB. Might be a starting point for understanding the hardware side of RS-232.

The protocol spec will drive your coding.