xref: /reactos/dll/shellext/acppage/ACPPage.cpp (revision ebaf247c)
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
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 
44 STDAPI DllCanUnloadNow()
45 {
46     if (g_ModuleRefCnt)
47         return S_FALSE;
48     return gModule.DllCanUnloadNow();
49 }
50 
51 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
52 {
53     return gModule.DllGetClassObject(rclsid, riid, ppv);
54 }
55 
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 
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 struct CCoInit
79 {
80     CCoInit() { hres = CoInitialize(NULL); }
81     ~CCoInit() { if (SUCCEEDED(hres)) { CoUninitialize(); } }
82     HRESULT hres;
83 };
84 
85 EXTERN_C
86 BOOL WINAPI GetExeFromLnk(PCWSTR pszLnk, PWSTR pszExe, size_t cchSize)
87 {
88     CCoInit init;
89     if (FAILED_UNEXPECTEDLY(init.hres))
90         return FALSE;
91 
92     CComPtr<IShellLinkW> spShellLink;
93     if (FAILED_UNEXPECTEDLY(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellLinkW, &spShellLink))))
94         return FALSE;
95 
96     CComPtr<IPersistFile> spPersistFile;
97     if (FAILED_UNEXPECTEDLY(spShellLink->QueryInterface(IID_PPV_ARG(IPersistFile, &spPersistFile))))
98         return FALSE;
99 
100     if (FAILED_UNEXPECTEDLY(spPersistFile->Load(pszLnk, STGM_READ)) || FAILED_UNEXPECTEDLY(spShellLink->Resolve(NULL, SLR_NO_UI | SLR_NOUPDATE | SLR_NOSEARCH)))
101         return FALSE;
102 
103     return !FAILED_UNEXPECTEDLY(spShellLink->GetPath(pszExe, cchSize, NULL, SLGP_RAWPATH));
104 }
105