bufstring.cpp
资源名称:shell.rar [点击查看]
上传用户:xhy777
上传日期:2007-02-14
资源大小:24088k
文件大小:1k
源码类别:
系统编程
开发平台:
Visual C++
- HRESULT CBufferedString::SetBSTR(BSTR bstr)
- {
- int len = lstrlenW(bstr) + 1;
- if (len < ARRAYSIZE(m_szTmpBuf)) {
- if (m_fFree) {
- LocalFree(m_pBuf);
- m_pBuf = m_szTmpBuf;
- m_fFree = FALSE;
- }
- } else {
- if (m_fFree) {
- LPTSTR psz = (LPTSTR)LocalReAlloc(m_pBuf, len * SIZEOF(TCHAR), LMEM_MOVEABLE | LMEM_ZEROINIT);
- if (psz) {
- m_pBuf = psz;
- }
- else {
- return E_OUTOFMEMORY;
- }
- } else {
- LPTSTR psz = (LPTSTR)LocalAlloc(LPTR, len * SIZEOF(TCHAR));
- if (psz) {
- m_pBuf = psz;
- m_fFree = TRUE;
- }
- else {
- return E_OUTOFMEMORY;
- }
- }
- }
- #ifdef UNICODE
- lstrcpy(m_pBuf, bstr);
- #else
- WideCharToMultiByte(CP_ACP, 0, bstr, -1, m_pBuf, len, NULL, NULL);
- #endif
- m_fSet = TRUE;
- return S_OK;
- }
English
