Click here to Skip to main content
12,627,681 members (33,368 online)
Click here to Skip to main content

Stats

144.6K views
2.4K downloads
81 bookmarked
Posted

Shell Extensions for .NET Assemblies

, 17 Nov 2005 Ms-PL
Shell extensions to distinguish between .NET assemblies and Win32 applications and libraries.
// AssemblyInfo.h : Declaration of the CAssemblyInfo

#pragma once
#include "resource.h"       // main symbols

#include "AsmShell.h"
#include <atlfile.h>
#include "rgsmap.h"
#include "Modules.h"

// Relative offsets in the FileType enumeration.
#define OFFSET_DOTNET 2
#define OFFSET_IA64   5
#define OFFSET_X64    10

// CAssemblyInfo

class ATL_NO_VTABLE CAssemblyInfo : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CAssemblyInfo, &CLSID_AssemblyInfo>,
	public ISupportErrorInfoImpl<&IID_IAssemblyInfo>,
	public IDispatchImpl<IAssemblyInfo, &IID_IAssemblyInfo, &LIBID_AsmShellLib, 1, 2>
{
public:
	CAssemblyInfo()
	{
	}

DECLARE_REGISTRY_RESOURCEID_EX(IDR_ASSEMBLYINFO)

BEGIN_REGISTRY_MAP(CAssemblyInfo)
	REGISTRY_GUID("CLSID", CLSID_AssemblyInfo)
	REGISTRY_GUID("LIBID", LIBID_AsmShellLib)
END_REGISTRY_MAP()

BEGIN_COM_MAP(CAssemblyInfo)
	COM_INTERFACE_ENTRY(IAssemblyInfo)
	COM_INTERFACE_ENTRY(ISupportErrorInfo)
	COM_INTERFACE_ENTRY2(IDispatch, IAssemblyInfo)
END_COM_MAP()

	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}
	
	void FinalRelease() 
	{
	}

public:

	// IAssemblyInfo
	STDMETHOD(IsAssembly)(BSTR path, VARIANT_BOOL* retVal);
	STDMETHOD(GetFileType)(BSTR path, FileType* retVal);
	STDMETHOD(GetPublicKeyToken)(BSTR path, BSTR* retVal);
	STDMETHOD(GetPublicKey)(BSTR path, SAFEARRAY** retVal);

private:

	// Declare a flagged enumeration and struct to hold information
	// for GetFileInfo().
	enum FILEINFOTYPE
	{
		FILEINFOTYPE_CORHEADER   = 1,
		FILEINFOTYPE_MACHINEARCH = 2
	};

	typedef struct FILEINFO
	{
		FILEINFOTYPE fit;
		VARIANT_BOOL varfCorHeader;
		WORD wMachineArch;
	} FILEINFO, *LPFILEINFO;

	HRESULT GetFileInfo(BSTR path, LPFILEINFO pFileInfo);
	HRESULT GetComDirectory(PIMAGE_NT_HEADERS pNtHeaders, PIMAGE_DATA_DIRECTORY pComDirectory);
	HRESULT GetMachineArch(LPVOID pFile, LPWORD pwMachine);
	HRESULT GetNtHeaders(LPVOID pFile, PIMAGE_NT_HEADERS* ppNtHeaders);
	HRESULT HasCorHeader(LPVOID pFile);
};

OBJECT_ENTRY_AUTO(__uuidof(AssemblyInfo), CAssemblyInfo)

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
Software Developer 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.

You may also be interested in...

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