ReactOS  0.4.15-dev-439-g292f67a
sendmail.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: sendmail
3  * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4  * PURPOSE: DeskLink implementation
5  * COPYRIGHT: Copyright 2019 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6  */
7 
8 #include "precomp.hpp"
9 
11 
12 BEGIN_OBJECT_MAP(ObjectMap)
13  OBJECT_ENTRY(CLSID_DeskLinkDropHandler, CDeskLinkDropHandler)
15 
19 
20 static BOOL
22 {
23  HANDLE hFile;
27  {
29  return TRUE;
30  }
31  return FALSE;
32 }
33 
34 static HRESULT
36 {
37  WCHAR szTarget[MAX_PATH], szSendToFile[MAX_PATH];
38 
39  LoadStringW(g_hModule, IDS_DESKLINK, szTarget, _countof(szTarget));
40  StringCbCatW(szTarget, sizeof(szTarget), L".DeskLink");
41 
42  StringCbCopyW(szSendToFile, sizeof(szSendToFile), pszSendTo);
43  PathAppendW(szSendToFile, szTarget);
44 
45  if (!CreateEmptyFile(szSendToFile))
46  {
47  ERR("CreateEmptyFile('%ls')\n", szSendToFile);
48  return E_FAIL;
49  }
50  return S_OK;
51 }
52 
53 static HRESULT
55 {
57  SHGFP_TYPE_DEFAULT, pszPath);
58 }
59 
61 {
62  if (g_ModuleRefCnt)
63  return S_FALSE;
64  return gModule.DllCanUnloadNow();
65 }
66 
68 {
69  TRACE("CLSID:%s,IID:%s\n", wine_dbgstr_guid(&rclsid), wine_dbgstr_guid(&riid));
70 
72 
73  TRACE("-- pointer to class factory: %p\n", *ppv);
74 
75  return hr;
76 }
77 
79 {
82  return hr;
83 
84  WCHAR szSendTo[MAX_PATH];
85  hr = GetDefaultUserSendTo(szSendTo);
86  if (SUCCEEDED(hr))
87  CreateSendToDeskLink(szSendTo);
88 
89  return S_OK;
90 }
91 
93 {
96  return hr;
97 
98  return S_OK;
99 }
100 
101 HRESULT
103  LPCWSTR pszLinkPath,
104  LPCWSTR pszTargetPath OPTIONAL,
105  LPCITEMIDLIST pidlTarget OPTIONAL,
106  LPCWSTR pszArg OPTIONAL,
108  LPCWSTR pszIconPath OPTIONAL,
109  INT iIconNr OPTIONAL,
110  LPCWSTR pszComment OPTIONAL)
111 {
113  HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL,
114  CLSCTX_INPROC_SERVER,
115  IID_PPV_ARG(IShellLinkW, &psl));
116  if (FAILED_UNEXPECTEDLY(hr))
117  return hr;
118 
119  if (pszTargetPath)
120  {
121  hr = psl->SetPath(pszTargetPath);
122  if (FAILED_UNEXPECTEDLY(hr))
123  return hr;
124  }
125  else if (pidlTarget)
126  {
127  hr = psl->SetIDList(pidlTarget);
128  if (FAILED_UNEXPECTEDLY(hr))
129  return hr;
130  }
131  else
132  {
133  ERR("invalid argument\n");
134  return E_INVALIDARG;
135  }
136 
137  if (pszArg)
138  hr = psl->SetArguments(pszArg);
139 
140  if (pszDir)
141  hr = psl->SetWorkingDirectory(pszDir);
142 
143  if (pszIconPath)
144  hr = psl->SetIconLocation(pszIconPath, iIconNr);
145 
146  if (pszComment)
147  hr = psl->SetDescription(pszComment);
148 
150  hr = psl->QueryInterface(IID_PPV_ARG(IPersistFile, &ppf));
151  if (FAILED_UNEXPECTEDLY(hr))
152  return hr;
153 
154  hr = ppf->Save(pszLinkPath, TRUE);
155  if (FAILED_UNEXPECTEDLY(hr))
156  return hr;
157 
158  return hr;
159 }
160 
162 {
163  TRACE("%p 0x%x %p\n", hInstance, dwReason, fImpLoad);
165  {
167  gModule.Init(ObjectMap, hInstance, NULL);
169  }
170  else if (dwReason == DLL_PROCESS_DETACH)
171  {
172  gModule.Term();
173  }
174  return TRUE;
175 }
#define STDAPI
Definition: basetyps.h:41
HRESULT DllCanUnloadNow()
Definition: atlbase.h:928
#define REFIID
Definition: guiddef.h:118
HRESULT DllRegisterServer(BOOL bRegTypeLib=TRUE)
Definition: atlbase.h:940
#define CloseHandle
Definition: compat.h:407
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
Definition: sendmail.cpp:67
static BOOL CreateEmptyFile(LPCWSTR pszFile)
Definition: sendmail.cpp:21
#define OBJECT_ENTRY(clsid, class)
Definition: atlcom.h:653
REFIID riid
Definition: precomp.h:44
#define REFCLSID
Definition: guiddef.h:117
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
REFIID LPVOID * ppv
Definition: atlbase.h:39
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
const char * wine_dbgstr_guid(const GUID *guid)
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
static HRESULT CreateSendToDeskLink(LPCWSTR pszSendTo)
Definition: sendmail.cpp:35
#define IID_PPV_ARG(Itype, ppType)
#define E_FAIL
Definition: ddrawi.h:102
STDAPI DllUnregisterServer(void)
Definition: sendmail.cpp:92
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int32_t INT
Definition: typedefs.h:57
CComModule gModule
Definition: sendmail.cpp:16
void Term()
Definition: atlbase.h:820
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
#define FILE_SHARE_READ
Definition: compat.h:125
BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
Definition: path.c:121
HRESULT CreateShellLink(LPCWSTR pszLinkPath, LPCWSTR pszTargetPath OPTIONAL, LPCITEMIDLIST pidlTarget OPTIONAL, LPCWSTR pszArg OPTIONAL, LPCWSTR pszDir OPTIONAL, LPCWSTR pszIconPath OPTIONAL, INT iIconNr OPTIONAL, LPCWSTR pszComment OPTIONAL)
Definition: sendmail.cpp:102
HRESULT Init(_ATL_OBJMAP_ENTRY *p, HINSTANCE, const GUID *plibid)
Definition: atlbase.h:797
HINSTANCE hInstance
Definition: charmap.c:20
#define IDS_DESKLINK
Definition: resource.h:13
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define GENERIC_WRITE
Definition: nt_native.h:90
#define S_FALSE
Definition: winerror.h:2357
#define E_INVALIDARG
Definition: ddrawi.h:101
HRESULT DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
Definition: atlbase.h:935
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DllMain(IN HINSTANCE hinstDLL, IN DWORD dwReason, IN LPVOID lpvReserved)
Definition: kbsdll.c:83
#define DLL_PROCESS_DETACH
Definition: compat.h:119
DWORD dwReason
Definition: sendmail.cpp:161
STDAPI_(BOOL) DllMain(HINSTANCE hInstance
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:78
#define _countof(array)
Definition: sndvol32.h:68
#define CSIDL_SENDTO
Definition: shlobj.h:2021
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
_In_ LPCSTR pszDir
Definition: shellapi.h:580
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
STDAPI DllCanUnloadNow(void)
Definition: sendmail.cpp:60
DWORD LPVOID fImpLoad
Definition: sendmail.cpp:162
WINE_DEFAULT_DEBUG_CHANNEL(sendmail)
LONG g_ModuleRefCnt
Definition: sendmail.cpp:17
_In_ HANDLE hFile
Definition: mswsock.h:90
return TRUE
Definition: sendmail.cpp:174
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
#define ERR(fmt,...)
Definition: debug.h:110
#define S_OK
Definition: intsafe.h:59
#define CREATE_ALWAYS
Definition: disk.h:72
STDAPI DllRegisterServer(void)
Definition: sendmail.cpp:78
#define CreateFileW
Definition: compat.h:409
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2208
HINSTANCE g_hModule
Definition: sendmail.cpp:18
#define BEGIN_OBJECT_MAP(x)
Definition: atlcom.h:649
HRESULT DllUnregisterServer(BOOL bUnRegTypeLib=TRUE)
Definition: atlbase.h:945
WCHAR * LPWSTR
Definition: xmlstorage.h:184
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
static HRESULT GetDefaultUserSendTo(LPWSTR pszPath)
Definition: sendmail.cpp:54
#define SUCCEEDED(hr)
Definition: intsafe.h:57
#define END_OBJECT_MAP()
Definition: atlcom.h:651
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68