Serial port communication app
In all the test that could be an error. Do you really want to continue if there is an error?
Seems counterproductive to generate an error message and continue running. That will just generate more spurious errors.

if(hSerial==INVALID_HANDLE_VALUE)
{
    throw std::runtime_error("Insert error message");
}


Then just wrap your code in a try catch block:

try
{
    ... Code here
}
catch(std::exception const&amp; e)
{
    std::cerr &lt;&lt; "Exception: " &lt;&lt; e.what() &lt;&lt; "\n";
    throw; // re-throw so the OS can provide help if available.
}
catch(...)
{
    std::cerr &lt;&lt; "Exception: Unknown ...\n";
    throw;
}