Click here to Skip to main content
14,691,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
As I have saave Hexadecimal Data To Database I have to convert it into CString.
But when I convert char array to CString ,nothing gets saved in Database and
thus instrument reading from Database does not work.This is because CString remains empty.Please help on this issue.

char ch[19];
   ch[0] = 0x01;
   ch[1] = 0x01;
   ch[2] = 0x01;  //Single wavelength 0x00 ,double wavelenth = 0x01
   ch[3] = 0x02;  //Main Wavelength
   ch[4] = 0x00;  //Secondary wavelength
   ch[5] = 0x01;  //third Wavelength
   ch[6] = 0x01;  //start column
   ch[7] = 0x0C;  //end column
   ch[8] = 0x05;   //shake rate  0x01 - 0x09
   ch[9] = 0x00;   //shake time  0x01 - 0xF0
   ch[10] = 0x01;
   ch[11] = 0x01;
   ch[12] = 0x55;
   ch[13] = 0x55;
   ch[14] = 0x55;
   ch[15] = 0x55;
   ch[16] = 0x55;
   ch[17] = 0x77;
   ch[18] = '\0';
   CString strData(ch);
   MessageBox(strData,_T("TITLE"),MB_OK);
Posted
Updated 8-Dec-12 0:30am
v2

Try it by your own format :) :
void BuildByteString(BYTE* pbyData, UINT uiDataLen, CString& cszReceiver)
{
  cszReceiver.Empty();
  while (uiDataLen--) {
    cszReceiver.AppendFormat(_T("0x%02u"), *pbyData++);
  }
}
   
v2
Actually Problem was that ch[4] = 0x00; and ch[9] = 0x00; It was causing CString to terminate.So I changed Protocol And Remove The Need Of 0x00 and passed other value like 0x01 And things worked.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900