⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memutil.h

📁 Windows CE 6.0 Server 源码
💻 H
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft shared
// source or premium shared source license agreement under which you licensed
// this source code. If you did not accept the terms of the license agreement,
// you are not authorized to use this source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the SOURCE.RTF on your install media or the root of your tools installation.
// THE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//+---------------------------------------------------------------------------------
//
//
// File:
//      memutil.h
//
// Contents:
//
//      Memory utilities
//
//----------------------------------------------------------------------------------

#ifndef _MEMUTIL_H_INCLUDED
#define _MEMUTIL_H_INCLUDED

class CMemWStr
{
  private:
    WCHAR *m_pwstr;
    
  public:  
    CMemWStr() {m_pwstr = NULL;}
    ~CMemWStr() {reset(); }
    inline void reset() { if (m_pwstr) delete [] m_pwstr;  m_pwstr = NULL;}
    inline WCHAR * get() {return m_pwstr;}
    inline void set(WCHAR *pwstr) {reset() ; m_pwstr = pwstr;}
    inline BOOL isEmpty() { return (!m_pwstr);}
    inline WCHAR * transfer() { WCHAR *ptemp = m_pwstr; m_pwstr = NULL; return ptemp; }
    inline void alloc_copy(WCHAR *pwstr) { 
        reset() ; 
        if (pwstr)
        	{
	            m_pwstr = new WCHAR[wcslen(pwstr) + 1];
	        	if (m_pwstr)
	        		wcscpy(m_pwstr, pwstr);
        	}
        }
    inline void alloc_sz(UINT nwchars) { reset() ; m_pwstr = (WCHAR *) new WCHAR[nwchars]; }
    inline WCHAR ** operator&() { reset() ; return &m_pwstr; }
};


// A utility BSTR class that auto-cleans its memory
class CMemBSTR
{
  private:
    BSTR m_bstr;
    
  public:  
    CMemBSTR() {m_bstr = NULL;}
    ~CMemBSTR() {reset(); }
    inline void reset() { if (m_bstr) SysFreeString(m_bstr);  m_bstr = NULL;}
    inline BSTR get() {return m_bstr;}
    inline void set(BSTR bstr) {reset() ; m_bstr = bstr;}
    inline BOOL isEmpty() { return (!m_bstr);}
    inline BSTR transfer() { BSTR bstrtemp = m_bstr; m_bstr = NULL; return bstrtemp; }
    inline void alloc_copy(BSTR bstr) { reset() ; m_bstr = SysAllocString(bstr); }
    inline BSTR * operator&() { reset() ; return &m_bstr; }
};

#endif _MEMUTIL_H_INCLUDED

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -