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

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
CtxCreateHash.dll
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
CtxVerifyHash.dll
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
// MenuItem.cpp : Implementation of CMenuItem
#include "stdafx.h"
#include "CtxTest.h"
#include "MenuItem.h"

#include <string>
#include <assert.h>

/////////////////////////////////////////////////////////////////////////////
// CMenuItem
HRESULT CMenuItem::InvokeCommand ( LPCMINVOKECOMMANDINFO pCmdInfo )
{
    // If lpVerb really points to a std::string,
    //   ignore this function call and bail out.
    if ( 0 != HIWORD( pCmdInfo->lpVerb ) ) { return E_INVALIDARG; }

    // Get the command index - the only valid one is 0.
    switch( LOWORD( pCmdInfo->lpVerb ) )
    {
        case 0:
        {

            MessageBox( pCmdInfo->hwnd, file.c_str(),
                      _T("Context Menu Test"), MB_ICONINFORMATION );       

            return S_OK;
            break;
        }
     
        default:
            assert( false );           
            break;
    }

    return E_INVALIDARG;
}

HRESULT CMenuItem::GetCommandString( UINT idCmd, UINT uFlags,
                     UINT* pwReserved, LPSTR pszName, UINT cchMax )
{

    pwReserved;         // Warning C4100 suppression

    // Check idCmd, it must be 0 since we have only one menu item.
    if ( 0 != idCmd ) { return E_INVALIDARG; }
 
    // If Explorer is asking for a help std::string, copy our std::string
    //   into the supplied buffer.
    if( uFlags & GCS_HELPTEXT )
    {        
        if ( uFlags & GCS_UNICODE )
        {
            LPWSTR szText = L"Context Menu Test Description";
            // We need to cast pszName to a Unicode std::string, and then use the
            // Unicode std::string copy API.
            lstrcpynW ( reinterpret_cast<LPWSTR>( pszName ), szText, cchMax );
        }
        else
        {
            LPSTR szText = "Context Menu Test Description";
            // Use the ANSI std::string copy API to return the help std::string.
            lstrcpynA ( pszName, szText, cchMax );
        }

        return S_OK;
    }

    return E_INVALIDARG;
}

HRESULT CMenuItem::QueryContextMenu( HMENU hmenu, UINT uMenuIndex,
                       UINT uidFirstCmd, UINT uidLastCmd, UINT uFlags )
{   
    uidFirstCmd;        // Suppression Warning C4100
    uidLastCmd;         // Suppression Warning C4100

    // If the flags include CMF_DEFAULTONLY then we shouldn't do anything.
    if( uFlags & CMF_DEFAULTONLY )
        { return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, 0 ); }

    InsertMenu( hmenu, uMenuIndex, MF_BYPOSITION,
                uidFirstCmd, _T("Context Menu Test") );

    return MAKE_HRESULT( SEVERITY_SUCCESS, FACILITY_NULL, 1 );
}

STDMETHODIMP CMenuItem::Initialize( LPCITEMIDLIST pidlFolder,
                                      LPDATAOBJECT pDataObj, HKEY hProgID )
{
    pidlFolder;     // Warning C4100 suppression
    hProgID;        // Warning C4100 suppression

    FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
    STGMEDIUM stg = { TYMED_HGLOBAL };
    HDROP     hDrop;

    // Look for CF_HDROP data in the data object. If there
    // is no such data, return an error back to Explorer.
    if( FAILED( pDataObj->GetData ( &fmt, &stg ) ))
        { return E_INVALIDARG; }

    // Get a pointer to the actual data.
    hDrop = static_cast<HDROP>( GlobalLock ( stg.hGlobal ) );

    // Make sure it worked.
    if( NULL == hDrop )
        { return E_INVALIDARG; }

    // Sanity check - make sure there is at least one filename.
    UINT uNumFiles = DragQueryFile( hDrop, static_cast<UINT>(-1), NULL, 0 );    
    if( 0 == uNumFiles )
    {
        GlobalUnlock ( stg.hGlobal );
        ReleaseStgMedium ( &stg );

        return E_INVALIDARG;
    }

    HRESULT hr = S_OK;

    // The author has encountered situations where
    //   MAX_PATH*2 was a bit too small...
    TCHAR szFile[ MAX_PATH * 4 + 1 ];

    DragQueryFile( static_cast<HDROP>( stg.hGlobal ),
                   0 /*first file*/, szFile, MAX_PATH * 4 );

    file = szFile;

    GlobalUnlock ( stg.hGlobal );
    ReleaseStgMedium ( &stg );

    return hr;
}

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)

Share

About the Author

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

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