Click here to Skip to main content
15,884,838 members
Articles / Desktop Programming / ATL

A File Checksum Shell Menu Extension DLL

Rate me:
Please Sign up or sign in to vote.
4.89/5 (34 votes)
23 May 2008LGPL315 min read 250.9K   6K   116  
Create a File Checksum Shell Menu Extension using ATL and Crypto++
// VerifyHash.h : Declaration of the CVerifyHash

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

#include "CtxVerifyHash.h"


#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif



// CVerifyHash

class ATL_NO_VTABLE CVerifyHash :
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CVerifyHash, &CLSID_VerifyHash>,
	public IDispatchImpl<IVerifyHash, &IID_IVerifyHash, &LIBID_CtxVerifyHashLib,
           /*wMajor =*/ 1, /*wMinor =*/ 0>,
    public IShellExtInit,
    public IContextMenu
{
public:
    CVerifyHash() { }

    protected:

    // Parallel Vectors of various hashes and hash values
    //   (in string format, not byte) for a given file
    //
    //   file = "C:\Winnt\text.txt"
    //
    //   hashes[0] = "MD5"
    //   hashes[1] = "SHA-1"
    //   hashes[2] = "SHA-256"
    //
    //   filehashes[0] = "CD5B65B7ACDBA247EDE28FBA169F2F26"
    //   filehashes[1] = "5751B71EFED61D91B3AD048C0C81F15397DAF434"
    //   filehashes[2] = "9AE08AA516BA5739 ... 282C16841B9866F2"
    bool CalculateFileHashes( const std::wstring& filename,
                              std::vector< std::wstring >& hashes,
                              std::vector< std::wstring >& filehashes );

    // Transforms
    //   'CD4FE51FD1C9A4F311BA0E7E920FB957D2E6DB804AB00FDFEBDFDBA9BB586172'
    // to
    //   'CD4FE51FD1C9A4F3...EBDFDBA9BB586172
    //
    // Useful for MessageBoxes to keep the size down
    //   Starts snipping when hash.length() > 32
    std::wstring Snip( const std::wstring& hash );

    // Retrieves the text on the Clipboard
    bool GetClipboardText( std::wstring& ClipboardText );

protected:
    std::vector< std::wstring > files;

    UINT uID;

public:
  // IShellExtInit
  STDMETHODIMP Initialize(LPCITEMIDLIST, LPDATAOBJECT, HKEY);

public:
  // IContextMenu
  STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO);
  STDMETHODIMP GetCommandString(UINT, UINT, UINT*, LPSTR, UINT);  
  STDMETHODIMP QueryContextMenu(HMENU, UINT, UINT, UINT, UINT);

DECLARE_REGISTRY_RESOURCEID(IDR_VERIFYHASH)

DECLARE_NOT_AGGREGATABLE(CVerifyHash)

BEGIN_COM_MAP(CVerifyHash)
	// COM_INTERFACE_ENTRY(IDispatch)
    COM_INTERFACE_ENTRY(IShellExtInit)
    COM_INTERFACE_ENTRY(IContextMenu)
END_COM_MAP()

	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct() { uID = -1; return S_OK; }

    void FinalRelease() { }

public:

};

OBJECT_ENTRY_AUTO(__uuidof(VerifyHash), CVerifyHash)

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 GNU Lesser General Public License (LGPLv3)


Written By
Systems / Hardware Administrator
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions