firemail

标题: 类型转换 [打印本页]

作者: hechengjin    时间: 2015-12-2 11:26
标题: 类型转换
本帖最后由 hechengjin 于 2016-3-22 11:40 编辑

set view(value) {
  
value instanceof Ci.nsIMsgDBView;
  
let totalMessages = value.db.folder.getTotalMessages(false);
  console.
log('TreeView.js set view',totalMessages, value) //[info] TreeView.js set view 1 [xpconnect wrapped (nsISupports, nsIMsgDBView, nsITreeView)]
}
  1. aEvent instanceof Ci.nsIDragSession
  2.     let messenger = Cc['@mozilla.org/messenger;1'].createInstance(Ci.nsIMessenger)
复制代码

作者: Qter    时间: 2020-1-1 14:47
CString->string
CString->std::string 例子:
CString strMfc="test";
std::string strStl;
strStl=strMfc.GetBuffer(0);
cfg.strServerIP = string((LPCTSTR)m_strAddr);

CString strdbPath;
wstring wdbPath =strdbPath.GetString();
wstring wdbPath =strdbPath.GetBuffer(strdbPath.GetLength());

std::string->CString 例子:
CString strMfc;
std::string strStl="test";
strMfc=strStl.c_str();
wstring filename;
CString str( filename.c_str() );

LPCTSTR str;
std::wstring cs = (LPCTSTR)str;
str = cs.c_str();


int CStringToInt(CString str)
{
        int nVal = atoi(str.GetBuffer(str.GetLength()));
        str.ReleaseBuffer();
        return nVal;
}


CString转char[]
char work_no[10];
Cstring m_csWorkno
memcpy(struResp.work_no,(LPCTSTR)m_csWorkno,m_csWorkno.GetLength());


string 转 char[]
strncpy_s(resWebConRes.mainAccount,strposTerminalNbr.c_str(),strposTerminalNbr.length());


CString转char*
char*pBuf=str.GetBuffer(0);
char*sz=str.GetBuffer(str.GetLength());
可以直接强制类型转换(LPTSTR)(LPCTSTR)str,即为char*类型
GetBuffer是返回一个锁定的内存地址,参数是指要锁定的内存长度

char转CString

CString str;
char a[]="121a";
str.Format(%s,a);
cout<<str<<endl;


char[] 转 string
        char terminal_no[64]="";转string terminal_no
        terminal_no = (string) terminal_no;
        string strworkno(pworkno);

int -> char*
char DB_MyBusinessType[3]={0};//我平台业务类型 00-未知 01-支付费转话费
        sprintf(DB_MyBusinessType,"%02d",struReq->nBusinessType) ;




欢迎光临 firemail (http://firemail.wang:8088/) Powered by Discuz! X3