2 * Copyright 2015 Mark Jansen
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <shellutils.h>
23 HMODULE g_hModule
= NULL
;
24 LONG g_ModuleRefCnt
= 0;
26 class CLayerUIPropPageModule
: public CComModule
35 BEGIN_OBJECT_MAP(ObjectMap
)
36 OBJECT_ENTRY(CLSID_CLayerUIPropPage
, CLayerUIPropPage
)
39 CLayerUIPropPageModule gModule
;
42 BOOL WINAPI
DllMain(HINSTANCE hInstance
, DWORD dwReason
, LPVOID lpReserved
)
46 case DLL_PROCESS_ATTACH
:
47 DisableThreadLibraryCalls(hInstance
);
48 g_hModule
= hInstance
;
49 gModule
.Init(ObjectMap
, hInstance
, NULL
);
56 STDAPI
DllCanUnloadNow()
60 return gModule
.DllCanUnloadNow();
63 STDAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
65 return gModule
.DllGetClassObject(rclsid
, riid
, ppv
);
68 STDAPI
DllRegisterServer()
72 hr
= gModule
.DllRegisterServer(FALSE
);
76 hr
= gModule
.UpdateRegistryFromResource(IDR_ACPPAGE
, TRUE
, NULL
);
83 STDAPI
DllUnregisterServer()
87 hr
= gModule
.DllUnregisterServer(FALSE
);
91 hr
= gModule
.UpdateRegistryFromResource(IDR_ACPPAGE
, FALSE
, NULL
);
100 CCoInit() { hres
= CoInitialize(NULL
); }
101 ~CCoInit() { if (SUCCEEDED(hres
)) { CoUninitialize(); } }
106 BOOL WINAPI
GetExeFromLnk(PCWSTR pszLnk
, PWSTR pszExe
, size_t cchSize
)
109 if (FAILED(init
.hres
))
112 CComPtr
<IShellLinkW
> spShellLink
;
113 if (FAILED(CoCreateInstance(CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
, IID_PPV_ARG(IShellLinkW
, &spShellLink
))))
116 CComPtr
<IPersistFile
> spPersistFile
;
117 if (FAILED(spShellLink
->QueryInterface(IID_PPV_ARG(IPersistFile
, &spPersistFile
))))
120 if (FAILED(spPersistFile
->Load(pszLnk
, STGM_READ
)) || FAILED(spShellLink
->Resolve(NULL
, SLR_NO_UI
| SLR_NOUPDATE
| SLR_NOSEARCH
)))
123 return SUCCEEDED(spShellLink
->GetPath(pszExe
, cchSize
, NULL
, SLGP_RAWPATH
));