| 1 | /* |
|---|
| 2 | * $Id$ |
|---|
| 3 | * Copyright 2008 The Eraser Project |
|---|
| 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" |
|---|
| 24 | #include "ShellExt_i.h" |
|---|
| 25 | #include "DllMain.h" |
|---|
| 26 | |
|---|
| 27 | CEraserShellExtModule _AtlModule; |
|---|
| 28 | CEraserShellExtApp theApp; |
|---|
| 29 | BEGIN_MESSAGE_MAP(CEraserShellExtApp, CWinApp) |
|---|
| 30 | END_MESSAGE_MAP() |
|---|
| 31 | |
|---|
| 32 | BOOL CEraserShellExtApp::InitInstance() |
|---|
| 33 | { |
|---|
| 34 | return CWinApp::InitInstance(); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | int CEraserShellExtApp::ExitInstance() |
|---|
| 38 | { |
|---|
| 39 | return CWinApp::ExitInstance(); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | //Used to determine whether the DLL can be unloaded by OLE |
|---|
| 43 | STDAPI DllCanUnloadNow(void) |
|---|
| 44 | { |
|---|
| 45 | AFX_MANAGE_STATE(AfxGetStaticModuleState()); |
|---|
| 46 | return (AfxDllCanUnloadNow()==S_OK && _AtlModule.GetLockCount()==0) ? S_OK : S_FALSE; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | //Returns a class factory to create an object of the requested type |
|---|
| 51 | STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) |
|---|
| 52 | { |
|---|
| 53 | return _AtlModule.DllGetClassObject(rclsid, riid, ppv); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | // DllRegisterServer - Adds entries to the system registry |
|---|
| 58 | STDAPI DllRegisterServer(void) |
|---|
| 59 | { |
|---|
| 60 | // registers object, typelib and all interfaces in typelib |
|---|
| 61 | HRESULT hr = _AtlModule.DllRegisterServer(); |
|---|
| 62 | return hr; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | //DllUnregisterServer - Removes entries from the system registry |
|---|
| 67 | STDAPI DllUnregisterServer(void) |
|---|
| 68 | { |
|---|
| 69 | HRESULT hr = _AtlModule.DllUnregisterServer(); |
|---|
| 70 | return hr; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | //DllInstall - Adds/Removes entries to the system registry per user |
|---|
| 74 | // per machine. |
|---|
| 75 | STDAPI DllInstall(BOOL bInstall, LPCWSTR pszCmdLine) |
|---|
| 76 | { |
|---|
| 77 | HRESULT hr = E_FAIL; |
|---|
| 78 | static const wchar_t szUserSwitch[] = _T("user"); |
|---|
| 79 | |
|---|
| 80 | if (pszCmdLine != NULL) |
|---|
| 81 | { |
|---|
| 82 | if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0) |
|---|
| 83 | { |
|---|
| 84 | AtlSetPerUserRegistration(true); |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | if (bInstall) |
|---|
| 89 | { |
|---|
| 90 | hr = DllRegisterServer(); |
|---|
| 91 | if (FAILED(hr)) |
|---|
| 92 | { |
|---|
| 93 | DllUnregisterServer(); |
|---|
| 94 | } |
|---|
| 95 | } |
|---|
| 96 | else |
|---|
| 97 | { |
|---|
| 98 | hr = DllUnregisterServer(); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | return hr; |
|---|
| 102 | } |
|---|