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

Shell Extensions for .NET Assemblies

, 17 Nov 2005 Ms-PL
Shell extensions to distinguish between .NET assemblies and Win32 applications and libraries.
// AssemblyColumns.cpp : Implementation of CAssemblyColumns

#include "stdafx.h"
#include "AssemblyColumns.h"
#include <strsafe.h>

// CAssemblyColumns

STDMETHODIMP CAssemblyColumns::GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO* psci)
{
	if (dwIndex > 1)
		return S_FALSE;

	if (psci == NULL)
		return E_POINTER;

	psci->scid.fmtid = CLSID_AssemblyColumns;
	psci->scid.pid = dwIndex;
	psci->vt = VT_BSTR;
	psci->fmt = LVCFMT_LEFT;
	psci->csFlags = SHCOLSTATE_TYPE_STR | SHCOLSTATE_SLOW;

	switch (dwIndex)
	{
	case 0:
		psci->cChars = 20;
		StringCchCopyW(psci->wszTitle, MAX_COLUMN_NAME_LEN, CT2WEX<MAX_COLUMN_NAME_LEN>(m_strFormatTitle));
		StringCchCopyW(psci->wszDescription, MAX_COLUMN_DESC_LEN, CT2WEX<MAX_COLUMN_DESC_LEN>(m_strFormatDesc));
		break;

	case 1:
		psci->cChars = 20;
		StringCchCopyW(psci->wszTitle, MAX_COLUMN_NAME_LEN, CT2WEX<MAX_COLUMN_NAME_LEN>(m_strKeyTokenTitle));
		StringCchCopyW(psci->wszDescription, MAX_COLUMN_DESC_LEN, CT2WEX<MAX_COLUMN_DESC_LEN>(m_strKeyTokenDesc));
		break;

	default:
		return S_FALSE;
	}

	return S_OK;
}

STDMETHODIMP CAssemblyColumns::GetItemData(LPCSHCOLUMNID pscid, LPCSHCOLUMNDATA pscd, VARIANT* pvarData)
{
	BSTR bstrVal = NULL;
	FileType ft;
	HRESULT hr;

	if (!pscid || !pscd || !pvarData)
		return E_POINTER;

	if (CLSID_AssemblyColumns != pscid->fmtid)
		return S_FALSE;

	switch (pscid->pid)
	{
	case 0:
		// Get the file type.
		hr = m_spAsmInfo->GetFileType((BSTR)pscd->wszFile, &ft);
		if (FAILED(hr))
			return S_FALSE;

		// Return the appropriate format.
		switch (ft)
		{
		case Win32Executable:
			m_bstrWin32Executable.CopyTo(&bstrVal);
			break;

		case Win32Library:
			m_bstrWin32Library.CopyTo(&bstrVal);
			break;

		case DotNETExecutable:
			m_bstrNETExecutable.CopyTo(&bstrVal);
			break;

		case DotNETLibrary:
			m_bstrNETLibrary.CopyTo(&bstrVal);
			break;

		case DotNETModule:
			m_bstrNETModule.CopyTo(&bstrVal);
			break;

		case Win64ExecutableIA64:
			m_bstrWin32ExecutableIA64.CopyTo(&bstrVal);
			break;

		case Win64LibraryIA64:
			m_bstrWin32LibraryIA64.CopyTo(&bstrVal);
			break;

		case DotNETExecutableIA64:
			m_bstrNETExecutableIA64.CopyTo(&bstrVal);
			break;

		case DotNETLibraryIA64:
			m_bstrNETLibraryIA64.CopyTo(&bstrVal);
			break;

		case DotNETModuleIA64:
			m_bstrNETModuleIA64.CopyTo(&bstrVal);
			break;

		case Win64ExecutableX64:
			m_bstrWin32ExecutableX64.CopyTo(&bstrVal);
			break;

		case Win64LibraryX64:
			m_bstrWin32LibraryX64.CopyTo(&bstrVal);
			break;

		case DotNETExecutableX64:
			m_bstrNETExecutableX64.CopyTo(&bstrVal);
			break;

		case DotNETLibraryX64:
			m_bstrNETLibraryX64.CopyTo(&bstrVal);
			break;

		case DotNETModuleX64:
			m_bstrNETModuleX64.CopyTo(&bstrVal);
			break;

		default:
			return S_FALSE;
		}

		break;

	case 1:
		// Get the public key token. Return for anything other than S_OK
		// since S_FALSE indicates that the file was not an assembly.
		hr = m_spAsmInfo->GetPublicKeyToken((BSTR)pscd->wszFile, &bstrVal);
		if (S_OK != hr || NULL == bstrVal) return S_FALSE;

		break;

	default:
		return S_FALSE;
	}
	
	pvarData->vt = VT_BSTR;
	pvarData->bstrVal = bstrVal;
	return S_OK;
}

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, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Heath Stewart
Program Manager Microsoft
United States United States
Heath Stewart is a happily married software engineer originally from the Midwest and a graduate of Iowa State University. Heath start programming early in life and enjoys continuous research and development in new languages, frameworks, and platforms. Fluent in many different programming languages, he has developed many large-scale software solutions for companies in different areas, such as Internet filtering, intrusion detection systems, production management systems, and web applications for various purposes. He also enjoys photography.
 
Currently, Heath is a Program Manager in the Visual Studio Professional Deployment Experience (VSPro DEX) team at Microsoft. Previous to his employment, he was a Microsoft MVP for Visual C#.
 
He is also a CodeProject protector and is happy to help the development community.
Follow on   Twitter

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150129.1 | Last Updated 17 Nov 2005
Article Copyright 2002 by Heath Stewart
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid