Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
strret.cpp
Package: shell.rar [view]
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 3k
Category:
Windows Kernel
Development Platform:
Visual C++
- //+-------------------------------------------------------------------------
- //
- // Microsoft Windows
- //
- // Copyright (C) Microsoft Corporation, 1997 - 1999
- //
- // File: strret.cpp
- //
- //--------------------------------------------------------------------------
- ///////////////////////////////////////////////////////////////////////////////
- /* File: strret.cpp
- Description: Class to handle STRRET objects used in returning strings
- from the Windows Shell. Main function is to properly clean up any
- dynamic storage.
- Revision History:
- Date Description Programmer
- -------- --------------------------------------------------- ----------
- 07/01/97 Initial creation. BrianAu
- */
- ///////////////////////////////////////////////////////////////////////////////
- #include "pch.h"
- #pragma hdrstop
- #include "strret.h"
- StrRet::StrRet(
- LPITEMIDLIST pidl,
- UINT type
- ) : m_pMalloc(NULL)
- {
- uType = type;
- pOleStr = NULL;
- SHGetMalloc(&m_pMalloc);
- m_pidl = pidl;
- }
- StrRet::~StrRet(
- VOID
- )
- {
- FreeOleStr();
- if (NULL != m_pMalloc)
- {
- m_pMalloc->Release();
- }
- }
- StrRet::StrRet(const StrRet& rhs)
- {
- *this = rhs;
- }
- StrRet& StrRet::operator = (const StrRet& rhs)
- {
- if (this != &rhs)
- {
- if (NULL != m_pMalloc)
- m_pMalloc->Release();
- m_pMalloc = rhs.m_pMalloc;
- if (NULL != m_pMalloc)
- m_pMalloc->AddRef();
- m_pidl = rhs.m_pidl;
- switch(rhs.uType)
- {
- case STRRET_WSTR:
- CopyOleStr(rhs.pOleStr);
- break;
- case STRRET_CSTR:
- lstrcpynA(cStr, rhs.cStr, ARRAYSIZE(cStr));
- break;
- case STRRET_OFFSET:
- uOffset = rhs.uOffset;
- break;
- }
- }
- return *this;
- }
- VOID
- StrRet::FreeOleStr(
- VOID
- )
- {
- if (NULL != m_pMalloc &&
- STRRET_WSTR == uType &&
- NULL != pOleStr)
- {
- m_pMalloc->Free(pOleStr);
- pOleStr = NULL;
- }
- }
- VOID
- StrRet::CopyOleStr(
- LPCWSTR pszOle
- )
- {
- FreeOleStr();
- pOleStr = new WCHAR[lstrlenW(pszOle) + 1];
- if (NULL != pOleStr)
- {
- lstrcpyW(pOleStr, pszOle);
- }
- }
- LPTSTR
- StrRet::GetString(
- LPTSTR pszStr,
- INT cchStr
- ) const
- {
- switch(uType)
- {
- case STRRET_WSTR:
- #ifndef UNICODE
- WideCharToMultiByte(CP_ACP, 0, pOleStr, -1, pszStr, cchStr, NULL, NULL);
- #else
- lstrcpyn(pszStr, pOleStr, cchStr);
- #endif
- break;
- case STRRET_CSTR:
- #ifndef UNICODE
- lstrcpyn(pszStr, cStr, cchStr);
- #else
- MultiByteToWideChar(CP_ACP, 0, cStr, -1, pszStr, cchStr);
- #endif
- break;
- case STRRET_OFFSET:
- lstrcpyn(pszStr, (LPCTSTR)((LPBYTE)m_pidl + uOffset), cchStr);
- break;
- }
- return pszStr;
- }