Every API has a return value that you can check to see if the operation succeeded or resulted in an error.
This way you can determine what to return from your function based on the return value of the API.
For example, the
ReadFile
case would be some this like this -
if (FALSE == ReadFile(hCom,buffer,1,&d,NULL))
return 0;