javascript执行以下语句,传入变量到ocx。(注:ocp为ocx控件名)
  ocp.DataBuf = String.fromCharCode('129')+String.fromCharCode('130')+'a'+'汉';ocp控件中的DataBuf定义为CString。
接收unicode编码为129和130时变为“?”即0x3F
“a”能正常接收
“汉”在javascript中的编码是unicode方式:0x6C49 到VC中变为0xBABA后面的接收均正确,就是129和130的接收变成了“?”无法识别请问我应该在ocx,怎样定义接收类型,才能接收到128~256的特殊的编码

解决方案 »

  1.   

    BSTR 到 const char 怎么转换? _bstr_t bb = bStr;
    char* okChar = bb;
    这样转换,无法okChar无法得到128~255的值,被置为了“0x3F”
      

  2.   

    BSTR bstr;
    int nBstrLen = SysStringLen(bstr);
    int nAnsiLen = WideCharToMultiByte(CP_ACP, 0, bstr, nBstrLen, 0, 0, NULL, NULL);
    char * szAnsi = new char[nAnsiLen + 1];
    WideCharToMultiByte(CP_ACP, 0, bstr, nBstrLen, szAnsi, nAnsiLen, NULL, NULL);
    szAnsi[nAnsiLen] = 0;