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-2018 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 };
19
20 BEGIN_OBJECT_MAP(ObjectMap)
21 OBJECT_ENTRY(CLSID_CLayerUIPropPage, CLayerUIPropPage)
22 END_OBJECT_MAP()
23
24 CLayerUIPropPageModule gModule;
25
26 EXTERN_C
DllMain(HINSTANCE hInstance,DWORD dwReason,LPVOID lpReserved)27 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
28 {
29 switch (dwReason)
30 {
31 case DLL_PROCESS_ATTACH:
32 DisableThreadLibraryCalls(hInstance);
33 g_hModule = hInstance;
34 gModule.Init(ObjectMap, hInstance, NULL);
35 break;
36 case DLL_PROCESS_DETACH:
37 gModule.Term();
38 break;
39 }
40
41 return(TRUE);
42 }
43
DllCanUnloadNow()44 STDAPI DllCanUnloadNow()
45 {
46 if (g_ModuleRefCnt)
47 return S_FALSE;
48 return gModule.DllCanUnloadNow();
49 }
50
DllGetClassObject(REFCLSID rclsid,REFIID riid,LPVOID * ppv)51 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
52 {
53 return gModule.DllGetClassObject(rclsid, riid, ppv);
54 }
55
DllRegisterServer()56 STDAPI DllRegisterServer()
57 {
58 HRESULT hr;
59
60 hr = gModule.DllRegisterServer(FALSE);
61 if (FAILED(hr))
62 return hr;
63
64 return S_OK;
65 }
66
DllUnregisterServer()67 STDAPI DllUnregisterServer()
68 {
69 HRESULT hr;
70
71 hr = gModule.DllUnregisterServer(FALSE);
72 if (FAILED(hr))
73 return hr;
74
75 return S_OK;
76 }
77
78 EXTERN_C
GetExeFromLnk(PCWSTR pszLnk,PWSTR pszExe,size_t cchSize)79 BOOL WINAPI GetExeFromLnk(PCWSTR pszLnk, PWSTR pszExe, size_t cchSize)
80 {
81 CCoInit init;
82 if (FAILED_UNEXPECTEDLY(init.hr))
83 return FALSE;
84
85 CComPtr<IShellLinkW> spShellLink;
86 if (FAILED_UNEXPECTEDLY(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellLinkW, &spShellLink))))
87 return FALSE;
88
89 CComPtr<IPersistFile> spPersistFile;
90 if (FAILED_UNEXPECTEDLY(spShellLink->QueryInterface(IID_PPV_ARG(IPersistFile, &spPersistFile))))
91 return FALSE;
92
93 if (FAILED_UNEXPECTEDLY(spPersistFile->Load(pszLnk, STGM_READ)) || FAILED_UNEXPECTEDLY(spShellLink->Resolve(NULL, SLR_NO_UI | SLR_NOUPDATE | SLR_NOSEARCH)))
94 return FALSE;
95
96 return !FAILED_UNEXPECTEDLY(spShellLink->GetPath(pszExe, cchSize, NULL, SLGP_RAWPATH));
97 }
98