Click here to Skip to main content
15,892,927 members
Articles / Programming Languages / C++

Listing Used Files

Rate me:
Please Sign up or sign in to vote.
4.81/5 (95 votes)
29 Sep 2010CPOL11 min read 635.9K   23.2K   220  
A ShellExtension that lists all the used files in a folder.
// OpenFileFinder.cpp : Implementation of DLL Exports.


#include "stdafx.h"
#include "resource.h"
#include "OpenFileFinder.h"


class COpenFileFinderModule : public CAtlDllModuleT< COpenFileFinderModule >
{
public :
	DECLARE_LIBID(LIBID_OpenFileFinderLib)
	DECLARE_REGISTRY_APPID_RESOURCEID(IDR_OPENFILEFINDER, "{2FDEE381-5479-4AB6-89E6-FA6FD91FBAE3}")
};

COpenFileFinderModule _AtlModule;

class COpenFileFinderApp : public CWinApp
{
public:

// Overrides
    virtual BOOL InitInstance();
    virtual int ExitInstance();

    DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(COpenFileFinderApp, CWinApp)
END_MESSAGE_MAP()

COpenFileFinderApp theApp;

BOOL COpenFileFinderApp::InitInstance()
{
    return CWinApp::InitInstance();
}

int COpenFileFinderApp::ExitInstance()
{
    return CWinApp::ExitInstance();
}


// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    return (AfxDllCanUnloadNow()==S_OK && _AtlModule.GetLockCount()==0) ? S_OK : S_FALSE;
}


// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
    return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
}

typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
LPFN_ISWOW64PROCESS fnIsWow64Process;

BOOL IsWow64()
{
    BOOL bIsWow64 = FALSE;

    fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
        GetModuleHandle(TEXT("kernel32")),"IsWow64Process");
  
    if (NULL != fnIsWow64Process)
    {
        if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
        {
            // handle error
        }
    }
    return bIsWow64;
}


// DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer(void)
{
    if( IsWow64() )
    {
        AfxMessageBox( L"Cannot register 32bit of this dll, use 64 bit version instead" );
		return E_FAIL;
    }
	OSVERSIONINFO info = { 0 }; 
	info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx(&info); 
	if( info.dwMajorVersion != 5 && info.dwMajorVersion != 6 )
	{
		// since I have build the driver only for widows xp and vista, this application cannot run on other os versions.
		AfxMessageBox( L"Sorry this can only be installed only in windows XP/2003 and Vista" );
		return E_FAIL;
	}
    // registers object, typelib and all interfaces in typelib
    HRESULT hr = _AtlModule.DllRegisterServer(FALSE);
	return hr;
}


// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
	HRESULT hr = _AtlModule.DllUnregisterServer(FALSE);
	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 Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions