Click here to Skip to main content
15,888,286 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 251.4K   6K   116  
Create a File Checksum Shell Menu Extension using ATL and Crypto++
// Test 6.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <windows.h>

#include <iostream>
#include <string>

int main(int argc, char* argv[])
{
    // Open the clipboard
    if( FALSE == OpenClipboard( NULL ) ) 
        { return false; }
    
    // Empty Data...
    EmptyClipboard();

    HGLOBAL hClipboardText = NULL;
    std::wstring text = L"Albert Einstein said, Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.";
 
    // Allocate memory for the text
    hClipboardText = GlobalAlloc(GMEM_DDESHARE,
                                (text.length() + 1) * sizeof( wchar_t ) ); 


    if( NULL == hClipboardText ) 
    { 
        CloseClipboard(); 
        return -1; 
    }

    wchar_t* pClipboardText = static_cast<wchar_t*>( GlobalLock( hClipboardText ) );

    try
    {
        memcpy( pClipboardText, text.c_str(), text.length() * sizeof( wchar_t ) );

        // Assure NULL termination
        pClipboardText[ text.length() ] = L'\0';
    }

    catch( ... )
    {
        CloseClipboard();
 
        return -1;
    }

    std::wcout << L"Clipboard Text:" << std::endl << text << std::endl;

    GlobalUnlock( hClipboardText );

    // Place the text on the clipboard. 
    bool result = ( FALSE != SetClipboardData( CF_UNICODETEXT, hClipboardText ) );

    CloseClipboard();

    return 0;
}

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