ReactOS  0.4.13-dev-247-g0f29b3f
ACPPage.cpp
Go to the documentation of this file.
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 
14 
16 {
17 public:
18 };
19 
20 BEGIN_OBJECT_MAP(ObjectMap)
23 
25 
28 {
29  switch (dwReason)
30  {
31  case DLL_PROCESS_ATTACH:
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 
45 {
46  if (g_ModuleRefCnt)
47  return S_FALSE;
48  return gModule.DllCanUnloadNow();
49 }
50 
52 {
53  return gModule.DllGetClassObject(rclsid, riid, ppv);
54 }
55 
57 {
58  HRESULT hr;
59 
61  if (FAILED(hr))
62  return hr;
63 
64  return S_OK;
65 }
66 
68 {
69  HRESULT hr;
70 
72  if (FAILED(hr))
73  return hr;
74 
75  return S_OK;
76 }
77 
78 struct CCoInit
79 {
83 };
84 
86 inline ULONG
87 Win32DbgPrint(const char *filename, int line, const char *lpFormat, ...)
88 {
89  char Buffer[512];
90  char* Current = Buffer;
91  size_t Length = _countof(Buffer);
92  const char* fname = strrchr(filename, '\\');
93  if (fname == NULL)
94  {
95  fname = strrchr(filename, '/');
96  if (fname != NULL)
97  fname++;
98  }
99  else
100  fname++;
101 
102  if (fname == NULL)
103  fname = filename;
104 
105  StringCchPrintfExA(Current, Length, &Current, &Length, STRSAFE_NULL_ON_FAILURE, "%s:%d: ", fname, line);
106  va_list ArgList;
107  va_start(ArgList, lpFormat);
108  StringCchVPrintfExA(Current, Length, &Current, &Length, STRSAFE_NULL_ON_FAILURE, lpFormat, ArgList);
109  va_end(ArgList);
111  return 0;
112 }
113 
114 
115 EXTERN_C
116 BOOL WINAPI GetExeFromLnk(PCWSTR pszLnk, PWSTR pszExe, size_t cchSize)
117 {
118  CCoInit init;
119  if (FAILED_UNEXPECTEDLY(init.hres))
120  return FALSE;
121 
122  CComPtr<IShellLinkW> spShellLink;
123  if (FAILED_UNEXPECTEDLY(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellLinkW, &spShellLink))))
124  return FALSE;
125 
126  CComPtr<IPersistFile> spPersistFile;
127  if (FAILED_UNEXPECTEDLY(spShellLink->QueryInterface(IID_PPV_ARG(IPersistFile, &spPersistFile))))
128  return FALSE;
129 
130  if (FAILED_UNEXPECTEDLY(spPersistFile->Load(pszLnk, STGM_READ)) || FAILED_UNEXPECTEDLY(spShellLink->Resolve(NULL, SLR_NO_UI | SLR_NOUPDATE | SLR_NOSEARCH)))
131  return FALSE;
132 
133  return !FAILED_UNEXPECTEDLY(spShellLink->GetPath(pszExe, cchSize, NULL, SLGP_RAWPATH));
134 }
#define STDAPI
Definition: basetyps.h:41
HRESULT DllCanUnloadNow()
Definition: atlbase.h:928
~CCoInit()
Definition: ACPPage.cpp:81
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define REFIID
Definition: guiddef.h:113
#define TRUE
Definition: types.h:120
HRESULT DllRegisterServer(BOOL bRegTypeLib=TRUE)
Definition: atlbase.h:940
HRESULT hr
Definition: shlfolder.c:183
HRESULT hres
Definition: ACPPage.cpp:82
STRSAFEAPI StringCchVPrintfExA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags, STRSAFE_LPCSTR pszFormat, va_list argList)
Definition: strsafe.h:650
#define OBJECT_ENTRY(clsid, class)
Definition: atlcom.h:653
REFIID riid
Definition: precomp.h:44
uint16_t * PWSTR
Definition: typedefs.h:54
LONG g_ModuleRefCnt
Definition: ACPPage.cpp:13
#define REFCLSID
Definition: guiddef.h:112
#define _countof(array)
Definition: fontsub.cpp:30
REFIID LPVOID * ppv
Definition: atlbase.h:39
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
HMODULE g_hModule
Definition: ACPPage.cpp:12
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
EXTERN_C ULONG Win32DbgPrint(const char *filename, int line, const char *lpFormat,...)
Definition: ACPPage.cpp:87
const char * filename
Definition: ioapi.h:135
STRSAFEAPI StringCchPrintfExA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:575
#define IID_PPV_ARG(Itype, ppType)
static int init
Definition: wintirpc.c:33
void Term()
Definition: atlbase.h:820
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
Definition: ACPPage.cpp:51
DWORD dwReason
Definition: misc.cpp:154
HRESULT Init(_ATL_OBJMAP_ENTRY *p, HINSTANCE, const GUID *plibid)
Definition: atlbase.h:797
HINSTANCE hInstance
Definition: charmap.c:20
#define va_end(ap)
Definition: acmsvcex.h:90
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define S_FALSE
Definition: winerror.h:2357
HRESULT DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
Definition: atlbase.h:935
smooth NULL
Definition: ftsmooth.c:416
Definition: parser.c:48
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
EXTERN_C BOOL WINAPI GetExeFromLnk(PCWSTR pszLnk, PWSTR pszExe, size_t cchSize)
Definition: ACPPage.cpp:116
#define DLL_PROCESS_DETACH
Definition: compat.h:119
#define STGM_READ
Definition: objbase.h:916
STDAPI DllUnregisterServer()
Definition: ACPPage.cpp:67
CLayerUIPropPageModule gModule
Definition: ACPPage.cpp:24
LONG HRESULT
Definition: typedefs.h:77
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:35
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
CCoInit()
Definition: ACPPage.cpp:80
LPCWSTR lpFormat
Definition: trayclock.cpp:32
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3234
STDAPI DllCanUnloadNow()
Definition: ACPPage.cpp:44
#define S_OK
Definition: intsafe.h:59
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:1991
EXTERN_C BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
Definition: ACPPage.cpp:27
#define va_start(ap, A)
Definition: acmsvcex.h:91
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1897
#define STRSAFE_NULL_ON_FAILURE
Definition: ntstrsafe.h:47
unsigned int ULONG
Definition: retypes.h:1
const GUID CLSID_CLayerUIPropPage
#define BEGIN_OBJECT_MAP(x)
Definition: atlcom.h:649
HRESULT DllUnregisterServer(BOOL bUnRegTypeLib=TRUE)
Definition: atlbase.h:945
STDAPI DllRegisterServer()
Definition: ACPPage.cpp:56
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define EXTERN_C
Definition: basetyps.h:12
void WINAPI SHIM_OBJ_NAME() OutputDebugStringA(LPCSTR lpOutputString)
Definition: ignoredbgout.c:18
#define SUCCEEDED(hr)
Definition: intsafe.h:57
#define END_OBJECT_MAP()
Definition: atlcom.h:651