OSDN Git Service

ShellExtension: Fix an issue where the Shell Extension menu string did not switch...
[winmerge-jp/winmerge-jp.git] / ShellExtension / ShellExtension.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // ShellExtension.cpp : Implementation of DLL Exports.
3 //
4 /////////////////////////////////////////////////////////////////////////////
5 //    License (GPLv2+):
6 //    This program is free software; you can redistribute it and/or modify
7 //    it under the terms of the GNU General Public License as published by
8 //    the Free Software Foundation; either version 2 of the License, or (at
9 //    your option) any later version.
10 //
11 //    This program is distributed in the hope that it will be useful, but
12 //    WITHOUT ANY WARRANTY; without even the implied warranty of
13 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //    GNU General Public License for more details.
15 //
16 //    You should have received a copy of the GNU General Public License
17 //    along with this program; if not, write to the Free Software
18 //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /////////////////////////////////////////////////////////////////////////////
20 // Look at http://www.codeproject.com/shell/ for excellent guide
21 // to Windows Shell programming by Michael Dunn.
22 //
23 // $Id$
24
25 // Note: Proxy/Stub Information
26 //      To build a separate proxy/stub DLL,
27 //      run nmake -f ShellExtensionps.mk in the project directory.
28
29 #include "stdafx.h"
30 #include "resource.h"
31 #include <initguid.h>
32 #include "ShellExtension.h"
33 #include "ShellExtension_i.c"
34 #include "RegKey.h"
35
36 class CWinMergeShellModule : public ATL::CAtlDllModuleT< CWinMergeShellModule >
37 {
38 public :
39         DECLARE_LIBID(LIBID_SHELLEXTENSIONLib)
40         DECLARE_REGISTRY_APPID_RESOURCEID(IDR_WINMERGESHELL, "{06029E17-28B5-456A-B866-4E79D98612FD}")
41 };
42
43 class CWinMergeShellModule _AtlModule;
44
45 // DLL Entry Point
46 extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
47 {
48         hInstance;
49         return _AtlModule.DllMain(dwReason, lpReserved);
50 }
51
52 // Used to determine whether the DLL can be unloaded by OLE.
53 _Use_decl_annotations_
54 STDAPI DllCanUnloadNow(void)
55 {
56         return _AtlModule.DllCanUnloadNow();
57 }
58
59 // Returns a class factory to create an object of the requested type.
60 _Use_decl_annotations_
61 STDAPI DllGetClassObject(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ LPVOID* ppv)
62 {
63         return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
64 }
65
66 // DllRegisterServer - Adds entries to the system registry.
67 _Use_decl_annotations_
68 STDAPI DllRegisterServer(void)
69 {
70         // registers object, typelib and all interfaces in typelib
71         HRESULT hr = _AtlModule.DllRegisterServer();
72         return hr;
73 }
74
75 // DllUnregisterServer - Removes entries from the system registry.
76 _Use_decl_annotations_
77 STDAPI DllUnregisterServer(void)
78 {
79         HRESULT hr = _AtlModule.DllUnregisterServer();
80         return hr;
81 }
82
83 // DllInstall - Adds/Removes entries to the system registry per user per machine.
84 STDAPI DllInstall(BOOL bInstall, _In_opt_  LPCWSTR pszCmdLine)
85 {
86         HRESULT hr = E_FAIL;
87         static const wchar_t szUserSwitch[] = L"user";
88
89         if (pszCmdLine != nullptr)
90         {
91                 if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0)
92                 {
93                         ATL::AtlSetPerUserRegistration(true);
94                 }
95         }
96
97         if (bInstall)
98         {
99                 hr = DllRegisterServer();
100                 if (FAILED(hr))
101                 {
102                         DllUnregisterServer();
103                 }
104         }
105         else
106         {
107                 hr = DllUnregisterServer();
108         }
109
110         return hr;
111 }
112
113