I would suggest you replace your read loop with the following
DWORD dwBytesRead2 = 0;
while(1)
{
if(ReadFile(hSerial, szBuff3, 300, &dwBytesRead2, NULL)==true)
{
szBuff3[dwBytesRead2]=0;
dest = hexToAscii(szBuff3,destElem,dwBytesRead2);
cout<<"dest: "<<dest<<endl;
if(!ReadFile(hSerial, szBuff3, 300, &dwBytesRead2, NULL))
{
cout<<"error66"<<endl;
}
}
}
And add the following changes to the
hexToAscii()
function, to allow space for, and add the null terminator
ascArray = (char *)malloc (*destElements + 1);
ascArray[destIndex] = '\0';