Opc Client 写入String 问题

来源:互联网 发布:美工课小房子教案 编辑:程序博客网 时间:2024/06/05 02:02
 bool WriteOPCCItem(..., std::string strval,...)
{    ........
      VARIANT variant;
      variant.vt = VT_BST;
      wchar_t *pwchar;
      pwchar = WSTRFromString(strval.c_str());
      variant.bstrVal = SysAllocString(pwchar);  
      WSTRFree(pwchar );
      ........//写入值
}
wchar_t* WSTRFromString(const char *buf)
{
    intlength, i;
    wchar_t*temp;
    length = strlen(buf) + 1;
    temp = new wchar_t[strlen(buf) + 1];
    if(temp)
    {
        for(i=0; i<length; i++) temp[i] = (wchar_t) buf[i];
    }
    return temp;
}
void  WSTRFree(wchar_t *c)
{
    if (c == NULL)
        return;
    delete c;
}

    
0 0