Merge branch 'ntfs_rebase'
[reactos.git] / dll / shellext / acppage / ACPPage.cpp
1 /*
2 * PROJECT: ReactOS Compatibility Layer Shell Extension
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: acppage entrypoint
5 * COPYRIGHT: Copyright 2015 Mark Jansen (mark.jansen@reactos.org)
6 */
7
8 #include "precomp.h"
9
10 #include <shellutils.h>
11
12 HMODULE g_hModule = NULL;
13 LONG g_ModuleRefCnt = 0;
14
15 class CLayerUIPropPageModule : public CComModule
16 {
17 public:
18 void Term()
19 {
20 CComModule::Term();
21 }
22 };
23
24 BEGIN_OBJECT_MAP(ObjectMap)
25 OBJECT_ENTRY(CLSID_CLayerUIPropPage, CLayerUIPropPage)
26 END_OBJECT_MAP()
27
28 CLayerUIPropPageModule gModule;
29
30 EXTERN_C
31 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
32 {
33 switch (dwReason)
34 {
35 case DLL_PROCESS_ATTACH:
36 DisableThreadLibraryCalls(hInstance);
37 g_hModule = hInstance;
38 gModule.Init(ObjectMap, hInstance, NULL);
39 break;
40 }
41
42 return(TRUE);
43 }
44
45 STDAPI DllCanUnloadNow()
46 {
47 if (g_ModuleRefCnt)
48 return S_FALSE;
49 return gModule.DllCanUnloadNow();
50 }
51
52 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
53 {
54 return gModule.DllGetClassObject(rclsid, riid, ppv);
55 }
56
57 STDAPI DllRegisterServer()
58 {
59 HRESULT hr;
60
61 hr = gModule.DllRegisterServer(FALSE);
62 if (FAILED(hr))
63 return hr;
64
65 hr = gModule.UpdateRegistryFromResource(IDR_ACPPAGE, TRUE, NULL);
66 if (FAILED(hr))
67 return hr;
68
69 return S_OK;
70 }
71
72 STDAPI DllUnregisterServer()
73 {
74 HRESULT hr;
75
76 hr = gModule.DllUnregisterServer(FALSE);
77 if (FAILED(hr))
78 return hr;
79
80 hr = gModule.UpdateRegistryFromResource(IDR_ACPPAGE, FALSE, NULL);
81 if (FAILED(hr))
82 return hr;
83
84 return S_OK;
85 }
86
87 struct CCoInit
88 {
89 CCoInit() { hres = CoInitialize(NULL); }
90 ~CCoInit() { if (SUCCEEDED(hres)) { CoUninitialize(); } }
91 HRESULT hres;
92 };
93
94 EXTERN_C
95 BOOL WINAPI GetExeFromLnk(PCWSTR pszLnk, PWSTR pszExe, size_t cchSize)
96 {
97 CCoInit init;
98 if (FAILED(init.hres))
99 return FALSE;
100
101 CComPtr<IShellLinkW> spShellLink;
102 if (FAILED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellLinkW, &spShellLink))))
103 return FALSE;
104
105 CComPtr<IPersistFile> spPersistFile;
106 if (FAILED(spShellLink->QueryInterface(IID_PPV_ARG(IPersistFile, &spPersistFile))))
107 return FALSE;
108
109 if (FAILED(spPersistFile->Load(pszLnk, STGM_READ)) || FAILED(spShellLink->Resolve(NULL, SLR_NO_UI | SLR_NOUPDATE | SLR_NOSEARCH)))
110 return FALSE;
111
112 return SUCCEEDED(spShellLink->GetPath(pszExe, cchSize, NULL, SLGP_RAWPATH));
113 }