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

A File Checksum Shell Menu Extension DLL

, 23 May 2008
Create a File Checksum Shell Menu Extension using ATL and Crypto++
ctxcreatehash.zip
CtxCreateHash
CtxCreateHash
CreateHash.rgs
CtxCreateHash.def
CtxCreateHash.rgs
CtxCreateHash.vcproj.8.00.old
CtxCreateHashps.def
CtxCreateHashPS.vcproj.8.00.old
CtxCreateHash.sln.old
ctxcreatehash2005.zip
CreateHash.rgs
CtxCreateHash.aps
CtxCreateHash.def
CtxCreateHash.rgs
CtxCreateHashps.def
ctxcreatehashdll.zip
ctxverifyhash.zip
CtxVerifyHash
CtxVerifyHash
CtxVerifyHash.def
CtxVerifyHash.rgs
CtxVerifyHash.vcproj.8.00.old
CtxVerifyHashps.def
CtxVerifyHashPS.vcproj.8.00.old
VerifyHash.rgs
CtxVerifyHash.sln.old
ctxverifyhash2005.zip
CtxVerifyHash.aps
CtxVerifyHash.def
CtxVerifyHash.rgs
CtxVerifyHashps.def
VerifyHash.rgs
ctxverifyhashdll.zip
sample1.zip
Sample 1
Test 1.dsp
Test 1.dsw
sample2.zip
Sample 2
Test 2.dsp
Test 2.dsw
sample3.zip
Sample 3
Test 3.dsp
Test 3.dsw
sample4.zip
Sample 4
Test 4.dsp
Test 4.dsw
sample5.zip
Sample 5
CtxTest.def
CtxTest.dsp
CtxTest.dsw
CtxTestps.def
CtxTestps.mk
MenuItem.rgs
// 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)

About the Author

Jeffrey Walton
Systems / Hardware Administrator
United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140718.1 | Last Updated 24 May 2008
Article Copyright 2006 by Jeffrey Walton
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid