| [696] | 1 | /* |
|---|
| 2 | * $Id$ |
|---|
| [1360] | 3 | * Copyright 2008-2009 The Eraser Project |
|---|
| [696] | 4 | * Original Author: Kasra Nassiri <cjax@users.sourceforge.net> |
|---|
| 5 | * Modified By: Joel Low <lowjoel@users.sourceforge.net> |
|---|
| 6 | * |
|---|
| 7 | * This file is part of Eraser. |
|---|
| 8 | * |
|---|
| 9 | * Eraser is free software: you can redistribute it and/or modify it under the |
|---|
| 10 | * terms of the GNU General Public License as published by the Free Software |
|---|
| 11 | * Foundation, either version 3 of the License, or (at your option) any later |
|---|
| 12 | * version. |
|---|
| 13 | * |
|---|
| 14 | * Eraser is distributed in the hope that it will be useful, but WITHOUT ANY |
|---|
| 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
|---|
| 16 | * A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
|---|
| 17 | * |
|---|
| 18 | * A copy of the GNU General Public License can be found at |
|---|
| 19 | * <http://www.gnu.org/licenses/>. |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | #include "stdafx.h" |
|---|
| 23 | #include "resource.h" |
|---|
| [703] | 24 | #include "ShellExt_i.h" |
|---|
| [696] | 25 | #include "DllMain.h" |
|---|
| 26 | |
|---|
| [704] | 27 | CEraserShellExtModule _AtlModule; |
|---|
| 28 | CEraserShellExtApp theApp; |
|---|
| 29 | BEGIN_MESSAGE_MAP(CEraserShellExtApp, CWinApp) |
|---|
| [696] | 30 | END_MESSAGE_MAP() |
|---|
| 31 | |
|---|
| [768] | 32 | namespace { |
|---|
| 33 | void InvalidParameterHandler(const wchar_t* /*expression*/, const wchar_t* /*function*/, |
|---|
| 34 | const wchar_t* /*file*/, unsigned int /*line*/, uintptr_t /*pReserved*/) |
|---|
| 35 | { |
|---|
| 36 | } |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| [704] | 39 | BOOL CEraserShellExtApp::InitInstance() |
|---|
| [696] | 40 | { |
|---|
| [768] | 41 | _set_invalid_parameter_handler(InvalidParameterHandler); |
|---|
| [696] | 42 | return CWinApp::InitInstance(); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| [704] | 45 | int CEraserShellExtApp::ExitInstance() |
|---|
| [696] | 46 | { |
|---|
| 47 | return CWinApp::ExitInstance(); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | //Used to determine whether the DLL can be unloaded by OLE |
|---|
| 51 | STDAPI DllCanUnloadNow(void) |
|---|
| 52 | { |
|---|
| [705] | 53 | AFX_MANAGE_STATE(AfxGetStaticModuleState()); |
|---|
| 54 | return (AfxDllCanUnloadNow()==S_OK && _AtlModule.GetLockCount()==0) ? S_OK : S_FALSE; |
|---|
| [696] | 55 | } |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | //Returns a class factory to create an object of the requested type |
|---|
| 59 | STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) |
|---|
| 60 | { |
|---|
| [705] | 61 | return _AtlModule.DllGetClassObject(rclsid, riid, ppv); |
|---|
| [696] | 62 | } |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | // DllRegisterServer - Adds entries to the system registry |
|---|
| 66 | STDAPI DllRegisterServer(void) |
|---|
| 67 | { |
|---|
| [705] | 68 | // registers object, typelib and all interfaces in typelib |
|---|
| 69 | HRESULT hr = _AtlModule.DllRegisterServer(); |
|---|
| [696] | 70 | return hr; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | //DllUnregisterServer - Removes entries from the system registry |
|---|
| 75 | STDAPI DllUnregisterServer(void) |
|---|
| 76 | { |
|---|
| 77 | HRESULT hr = _AtlModule.DllUnregisterServer(); |
|---|
| 78 | return hr; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | //DllInstall - Adds/Removes entries to the system registry per user |
|---|
| [705] | 82 | // per machine. |
|---|
| [696] | 83 | STDAPI DllInstall(BOOL bInstall, LPCWSTR pszCmdLine) |
|---|
| 84 | { |
|---|
| [705] | 85 | HRESULT hr = E_FAIL; |
|---|
| 86 | static const wchar_t szUserSwitch[] = _T("user"); |
|---|
| [696] | 87 | |
|---|
| [705] | 88 | if (pszCmdLine != NULL) |
|---|
| 89 | { |
|---|
| 90 | if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0) |
|---|
| 91 | { |
|---|
| 92 | AtlSetPerUserRegistration(true); |
|---|
| 93 | } |
|---|
| 94 | } |
|---|
| [696] | 95 | |
|---|
| [705] | 96 | if (bInstall) |
|---|
| 97 | { |
|---|
| 98 | hr = DllRegisterServer(); |
|---|
| 99 | if (FAILED(hr)) |
|---|
| 100 | { |
|---|
| 101 | DllUnregisterServer(); |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | else |
|---|
| 105 | { |
|---|
| 106 | hr = DllUnregisterServer(); |
|---|
| 107 | } |
|---|
| [696] | 108 | |
|---|
| 109 | return hr; |
|---|
| 110 | } |
|---|