Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

The Mini Shell Extension Framework – Part III

, 18 Sep 2005
Discussion of a small C++ framework to create Windows shell extensions (IShellFolderImpl).
msf091.zip
include
columnprovider.rgs
contextmenu.rgs
contextmenu_sf.rgs
extension.rgs
extractimage_sf.rgs
infotip.rgs
infotip_sf.rgs
propertysheetext.rgs
propertysheetext_sf.rgs
shell32missing.def
shell32missing.lib
shellfolder.rgs
shellfolderwin98.rgs
vvvsample
Copy of sample1.vvv
menuicon.bmp
sample.def
sample.manifest
sample1.vvv
vvv.ico
vvvtest
sample.yyy
sample1.vvv
sample2.vvv
//
// (C) Copyright by Victor Derks <vba64@xs4all.nl>
//
// See README.TXT for the details of the software licence.
//
#pragma once


#include "macros.h"


namespace MSF
{

// Purpose: Management class for pidls. A CPidl class is owner of the wrapped ITEMIDLIST.
class CPidl
{
public:
	static ITEMIDLIST* Clone(const ITEMIDLIST* pidlSrc)
	{
		ATLASSERT(pidlSrc != NULL && "Why clone a NULL pointer?");

		ITEMIDLIST* pidl = ::ILClone(pidlSrc);
		RaiseExceptionIf(pidl == NULL, E_OUTOFMEMORY);

		return pidl;
	}


	static ITEMIDLIST* Combine(const ITEMIDLIST* pidl1, const ITEMIDLIST* pidl2)
	{
		ITEMIDLIST* pidl = ::ILCombine(pidl1, pidl2);
		RaiseExceptionIf(pidl == NULL && !(pidl1 == NULL && pidl == NULL), E_OUTOFMEMORY);

		return pidl;
	}


	static ITEMIDLIST* CreateFromPath(LPCTSTR pszPath)
	{
		ITEMIDLIST* pidl = ILCreateFromPath(pszPath);
		RaiseExceptionIf(pidl == NULL, E_OUTOFMEMORY);

		return pidl;
	}


	// Purpose: Small helper, returns NULL also for the tail element.
	static const ITEMIDLIST* GetNextItem(const ITEMIDLIST* pidl)
	{
		const ITEMIDLIST* pidlNext = ILGetNext(pidl);
		if (pidlNext != NULL && pidlNext->mkid.cb == 0)
		{
			pidlNext = NULL;
		}

		return pidlNext;
	}


	CPidl() throw() : m_pidl(NULL)
	{
	}


	// Purpose: special constructor for NULL pointer init.
	CPidl(int null) throw() : m_pidl(NULL)
	{
		(null);
		ATLASSERT(null == 0 && "Detected misuse of the special constructor");
	}


	CPidl(ITEMIDLIST* pidl) throw() : m_pidl(pidl)
	{
	}


	CPidl(const ITEMIDLIST* pidl) : m_pidl(Clone(pidl))
	{
	}


	CPidl(const ITEMIDLIST* pidl1, const ITEMIDLIST* pidl2) :
		m_pidl(Combine(pidl1, pidl2))
	{
	}


	CPidl(const CPidl& pidl1, const ITEMIDLIST* pidl2) :
		m_pidl(Combine(pidl1.m_pidl, pidl2))
	{
	}


	CPidl(const TCHAR* pszPath) :
		m_pidl(CreateFromPath(pszPath))
	{
	}


	~CPidl() throw()
	{
		ILFree(m_pidl);
	}


	void Attach(ITEMIDLIST* pidl) throw()
	{
		ILFree(m_pidl);
		m_pidl = pidl;
	}


	ITEMIDLIST* Detach() throw()
	{
		ITEMIDLIST* pidl = m_pidl;
		m_pidl = NULL;
		return pidl;
	}


	void CloneFrom(const ITEMIDLIST* pidl)
	{
		Attach(Clone(pidl));
	}


	ITEMIDLIST* Clone() const
	{
		return Clone(m_pidl);
	}


	void AppendID(const SHITEMID* pmkid) throw()
	{
		ITEMIDLIST* pidl = ILAppendID(m_pidl, pmkid, TRUE);
		RaiseExceptionIf(pidl == NULL, E_OUTOFMEMORY);

		m_pidl = pidl;
	}


	const ITEMIDLIST* get() const throw()
	{
		return m_pidl;
	}


	operator const ITEMIDLIST*() const throw()
	{
		return get();
	}


	const ITEMIDLIST* operator->() const throw()
	{
		return get();
	}


	UINT GetSize() const throw()
	{
		return ILGetSize(m_pidl);
	}


	// Purpose: Adres operator to be used for passing address to be used as an out-parameter.
	ITEMIDLIST** operator&() throw()
	{
		Attach(NULL);
		return &m_pidl;
	}

private:

	ITEMIDLIST* m_pidl;
};

} // namespace MSF

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Victor Derks
Software Developer (Senior) Schneider Electric
Netherlands Netherlands
Victor lives in Nijmegen, the oldest city in The Netherlands.
He studied Applied Physics in Delft and now works for GE Healthcare.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 18 Sep 2005
Article Copyright 2005 by Victor Derks
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid