windows-nt/Source/XPSP1/NT/shell/inc/memt.h
2020-09-26 16:20:57 +08:00

40 lines
669 B
C++

#ifndef __MEMORYTEMPLATES_H__
#define __MEMORYTEMPLATES_H__
template <class T>
inline HRESULT SHLocalAlloc(ULONG cb, T **ppv)
{
*ppv = (T *) LocalAlloc(LPTR, cb);
return *ppv ? S_OK : E_OUTOFMEMORY;
}
template <class T>
inline HRESULT SHCoAlloc(ULONG cb, T **ppv)
{
*ppv = (T *) CoTaskMemAlloc(cb);
return *ppv ? S_OK : E_OUTOFMEMORY;
}
template <class T>
class CSmartCoTaskMem
{
protected:
T *p;
public:
CSmartCoTaskMem() { p = NULL; }
~CSmartCoTaskMem() { if (p) CoTaskMemFree(p); }
T** operator&()
{
ASSERT(p==NULL);
return &p;
}
operator T*() { return p; }
};
#endif // __MEMORYTEMPLATES_H__