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 HMODULE g_hModule
= NULL
;
22 LONG g_ModuleRefCnt
= 0;
24 class CLayerUIPropPageModule
: public CComModule
33 BEGIN_OBJECT_MAP(ObjectMap
)
34 OBJECT_ENTRY(CLSID_CLayerUIPropPage
, CLayerUIPropPage
)
37 CLayerUIPropPageModule gModule
;
40 BOOL WINAPI
DllMain(HINSTANCE hInstance
, DWORD dwReason
, LPVOID lpReserved
)
44 case DLL_PROCESS_ATTACH
:
45 DisableThreadLibraryCalls(hInstance
);
46 g_hModule
= hInstance
;
47 gModule
.Init(ObjectMap
, hInstance
, NULL
);
54 STDAPI
DllCanUnloadNow()
58 return gModule
.DllCanUnloadNow();
61 STDAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
63 return gModule
.DllGetClassObject(rclsid
, riid
, ppv
);
66 STDAPI
DllRegisterServer()
70 hr
= gModule
.DllRegisterServer(FALSE
);
74 hr
= gModule
.UpdateRegistryFromResource(IDR_ACPPAGE
, TRUE
, NULL
);
81 STDAPI
DllUnregisterServer()
85 hr
= gModule
.DllUnregisterServer(FALSE
);
89 hr
= gModule
.UpdateRegistryFromResource(IDR_ACPPAGE
, FALSE
, NULL
);
98 CCoInit() { hres
= CoInitialize(NULL
); }
99 ~CCoInit() { if (SUCCEEDED(hres
)) { CoUninitialize(); } }
104 BOOL WINAPI
GetExeFromLnk(PCWSTR pszLnk
, PWSTR pszExe
, size_t cchSize
)
107 if (FAILED(init
.hres
))
110 CComPtr
<IShellLinkW
> spShellLink
;
111 if (FAILED(CoCreateInstance(CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
, IID_PPV_ARG(IShellLinkW
, &spShellLink
))))
114 CComPtr
<IPersistFile
> spPersistFile
;
115 if (FAILED(spShellLink
->QueryInterface(IID_PPV_ARG(IPersistFile
, &spPersistFile
))))
118 if (FAILED(spPersistFile
->Load(pszLnk
, STGM_READ
)) || FAILED(spShellLink
->Resolve(NULL
, SLR_NO_UI
| SLR_NOUPDATE
| SLR_NOSEARCH
)))
121 return SUCCEEDED(spShellLink
->GetPath(pszExe
, cchSize
, NULL
, SLGP_RAWPATH
));