http://www.opc-china.com
下面的代码用于GSM MODEM AT指令下的STRING到UNICDE码的转换。
CString ExchangeMsg(CString msg)
{
CString retstr;
char aa[500]="";
int len=msg.GetLength();
BSTR x=msg. AllocSysString();
long num=*((long*)x-1);
for(int i=0;i<num;i+=1)
{
if(i>=len)
break;
char cc[10]="";
if((*x>>8)==0)
{
sprintf(aa,"%s00%x",aa,*x);
msg=msg.Right (msg.GetLength ()-1);
}
else
{
sprintf(aa,"%s%x",aa,*x);
msg=msg.Right (msg.GetLength ()-2);
i=i+1;
}
SysFreeString(x);
x=msg. AllocSysString();
}
SysFreeString(x);
char bb[10]="";
int len1=strlen(aa);
char txt[500]="";
if(len1%4!=0)
{
memcpy(txt,aa,(len1-3));
}
else
{
memcpy(txt,aa,len1);
}
if(num<=0x0f)
{
sprintf(bb,"0%x",num);
}
else
{
sprintf(bb,"%x",num);
}
retstr.Format ("%s%s",bb,txt);
retstr.MakeUpper ();
int msglth=retstr.GetLength();
return retstr;
}
OPC技术论坛 http://www.opc-china.com OPC服务器,客户程序技术讨论