I would appreciate a little help fixing a bug I have with the conversion of some point data I have that is currently in a unsigned character array (Technically a vector) to a CString.
Currently my code converts the data like this:
std::vector <unsigned char> points;
CString strResult;
int totalpoints = 0;
// Add point data in here (x,y)
// Tick up totalpoints
strResult = CString(reinterpret_cast<char*>(&points[0]), totalpoints * 4); // I did not write this line. I'm just trying to fix it
return strResult.AllocSysString();
The issue arises when something attempts to read the data back out of strResult. Some of the data changes. I believe this is because when CString converts chars it try's to make the same character in wide format, even if the underlying value is different.. For example if I pass it the value 147 I will instead see the value 8339. I can get the value 147 from 8339 if I cast it back into a unsigned char, but where this data ultimately goes I don't have control of it. It is expected that they will get 147 with out casting, not 8339.
So The question is, how do I change the conversion to fix this?
Update: I have been examine the hex values and when the values ending up being incorrect, it's because the high byte in the CString is set to 0x20
Update 2: It might also help clarify that existing data starts as two ints. One for x and one for y. They are separated into pairs of Bytes and stored into points.