Most of your code seems to be useless and the Unicode/char conversion parts are wrong.
The wrong parts that lead to the garbage values are:
strcpy(carrArray,(LPCSTR) (CStringA)getvalue);
strcpy(carrArray,CStringA(getvalue.GetString()).GetString());
getvalue.Format(L"%s",carrArray);
getvalue.Format(L"%hs",carrArray);
There is no need to copy the string multiple times to insert the character at increasing positions. Just use your
m_TxtSamplingFrequency
variable:
m_CntrlDisplay.GetWindowText(m_TxtSamplingFrequency);
if (usCurPos > m_TxtSamplingFrequency.GetLength())
usCurPos = m_TxtSamplingFrequency.GetLength();
m_TxtSamplingFrequency.Insert(usCurPos, _T('A'));
m_CntrlDisplay.SetWindowText(m_TxtSamplingFrequency);
usCurPos++;
m_CntrlDisplay.SetSel(usCurPos,usCurPos);