ReactOS 0.4.15-dev-7136-g77ab709
utils.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: shell32
3 * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4 * PURPOSE: Utility functions
5 * COPYRIGHT: Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8#include "precomp.h"
9
11
12static BOOL
16{
17 BOOL ret;
18
19 if (phToken == NULL)
20 {
22 return FALSE;
23 }
24
25 *phToken = NULL;
26
28 if (!ret && GetLastError() == ERROR_NO_TOKEN)
30
31 return ret;
32}
33
34/*************************************************************************
35 * SHSetFolderPathA (SHELL32.231)
36 *
37 * @see https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shsetfolderpatha
38 */
42 _In_ INT csidl,
43 _In_ HANDLE hToken,
45 _In_ LPCSTR pszPath)
46{
47 TRACE("(%d, %p, 0x%X, %s)\n", csidl, hToken, dwFlags, debugstr_a(pszPath));
48 CStringW strPathW(pszPath);
49 return SHSetFolderPathW(csidl, hToken, dwFlags, strPathW);
50}
51
52/*************************************************************************
53 * PathIsSlowA (SHELL32.240)
54 *
55 * @see https://learn.microsoft.com/en-us/windows/win32/api/shlobj/nf-shlobj-pathisslowa
56 */
60 _In_ LPCSTR pszFile,
61 _In_ DWORD dwAttr)
62{
63 TRACE("(%s, 0x%X)\n", debugstr_a(pszFile), dwAttr);
64 CStringW strFileW(pszFile);
65 return PathIsSlowW(strFileW, dwAttr);
66}
67
68/*************************************************************************
69 * ExtractIconResInfoA (SHELL32.221)
70 */
74 _In_ HANDLE hHandle,
76 _In_ WORD wIndex,
77 _Out_ LPWORD lpSize,
78 _Out_ LPHANDLE lpIcon)
79{
80 TRACE("(%p, %s, %u, %p, %p)\n", hHandle, debugstr_a(lpFileName), wIndex, lpSize, lpIcon);
81
82 if (!lpFileName)
83 return 0;
84
85 CStringW strFileNameW(lpFileName);
86 return ExtractIconResInfoW(hHandle, strFileNameW, wIndex, lpSize, lpIcon);
87}
88
89/*************************************************************************
90 * ShortSizeFormatW (SHELL32.204)
91 */
95 _In_ DWORD dwNumber,
96 _Out_writes_(0x8FFF) LPWSTR pszBuffer)
97{
98 TRACE("(%lu, %p)\n", dwNumber, pszBuffer);
99 return StrFormatByteSizeW(dwNumber, pszBuffer, 0x8FFF);
100}
101
102/*************************************************************************
103 * SHOpenEffectiveToken (SHELL32.235)
104 */
106{
107 TRACE("%p\n", phToken);
109}
110
111/*************************************************************************
112 * SHGetUserSessionId (SHELL32.248)
113 */
115{
116 DWORD dwSessionId, dwLength;
117 BOOL bOpenToken = FALSE;
118
119 TRACE("%p\n", hToken);
120
121 if (!hToken)
122 bOpenToken = SHOpenEffectiveToken(&hToken);
123
124 if (!hToken ||
125 !GetTokenInformation(hToken, TokenSessionId, &dwSessionId, sizeof(dwSessionId), &dwLength))
126 {
127 dwSessionId = 0;
128 }
129
130 if (bOpenToken)
131 CloseHandle(hToken);
132
133 return dwSessionId;
134}
135
136/*************************************************************************
137 * SHInvokePrivilegedFunctionW (SHELL32.246)
138 */
142 _In_ LPCWSTR pszName,
145{
146 TRACE("(%s %p %p)\n", debugstr_w(pszName), fn, lParam);
147
148 if (!pszName || !fn)
149 return E_INVALIDARG;
150
151 HANDLE hToken = NULL;
152 TOKEN_PRIVILEGES NewPriv, PrevPriv;
153 BOOL bAdjusted = FALSE;
154
155 if (SHOpenEffectiveToken(&hToken) &&
156 ::LookupPrivilegeValueW(NULL, pszName, &NewPriv.Privileges[0].Luid))
157 {
158 NewPriv.PrivilegeCount = 1;
160
161 DWORD dwReturnSize;
162 bAdjusted = ::AdjustTokenPrivileges(hToken, FALSE, &NewPriv,
163 sizeof(PrevPriv), &PrevPriv, &dwReturnSize);
164 }
165
166 HRESULT hr = fn(lParam);
167
168 if (bAdjusted)
169 ::AdjustTokenPrivileges(hToken, FALSE, &PrevPriv, 0, NULL, NULL);
170
171 if (hToken)
172 ::CloseHandle(hToken);
173
174 return hr;
175}
176
177/*************************************************************************
178 * SHTestTokenPrivilegeW (SHELL32.236)
179 *
180 * @see http://undoc.airesoft.co.uk/shell32.dll/SHTestTokenPrivilegeW.php
181 */
185 _In_opt_ HANDLE hToken,
187{
188 LUID Luid;
190 PTOKEN_PRIVILEGES pTokenPriv;
191 HANDLE hNewToken = NULL;
192 BOOL ret = FALSE;
193
194 TRACE("(%p, %s)\n", hToken, debugstr_w(lpName));
195
196 if (!lpName)
197 return FALSE;
198
199 if (!hToken)
200 {
201 if (!SHOpenEffectiveToken(&hNewToken))
202 goto Quit;
203
204 if (!hNewToken)
205 return FALSE;
206
207 hToken = hNewToken;
208 }
209
210 if (!LookupPrivilegeValueW(NULL, lpName, &Luid))
211 return FALSE;
212
213 dwLength = 0;
215 goto Quit;
216
218 if (!pTokenPriv)
219 goto Quit;
220
221 if (GetTokenInformation(hToken, TokenPrivileges, pTokenPriv, dwLength, &dwLength))
222 {
223 UINT iPriv, cPrivs;
224 cPrivs = pTokenPriv->PrivilegeCount;
225 for (iPriv = 0; !ret && iPriv < cPrivs; ++iPriv)
226 {
227 ret = RtlEqualLuid(&Luid, &pTokenPriv->Privileges[iPriv].Luid);
228 }
229 }
230
231 LocalFree(pTokenPriv);
232
233Quit:
234 if (hToken == hNewToken)
235 CloseHandle(hNewToken);
236
237 return ret;
238}
239
241{
243}
244
245/*************************************************************************
246 * IsSuspendAllowed (SHELL32.53)
247 */
249{
250 TRACE("()\n");
252}
253
254/*************************************************************************
255 * SHGetShellStyleHInstance (SHELL32.749)
256 */
258WINAPI
260{
263 HRESULT hr;
264 CStringW strShellStyle;
265
266 TRACE("SHGetShellStyleHInstance called\n");
267
268 /* First, attempt to load the shellstyle dll from the current active theme */
270 if (FAILED(hr))
271 goto DoDefault;
272
273 /* Strip the theme filename */
275
276 strShellStyle = szPath;
277 strShellStyle += L"\\Shell\\";
278 strShellStyle += szColorName;
279 strShellStyle += L"\\ShellStyle.dll";
280
282 if (hInst)
283 return hInst;
284
285 /* Otherwise, use the version stored in the System32 directory */
286DoDefault:
287 if (!ExpandEnvironmentStringsW(L"%SystemRoot%\\System32\\ShellStyle.dll",
289 {
290 ERR("Expand failed\n");
291 return NULL;
292 }
294}
295
296/*************************************************************************
297 * SHCreatePropertyBag (SHELL32.715)
298 */
300WINAPI
302{
304}
305
306/*************************************************************************
307 * SheRemoveQuotesA (SHELL32.@)
308 */
310WINAPI
312{
313 PCHAR pch;
314
315 if (*psz == '"')
316 {
317 for (pch = psz + 1; *pch && *pch != '"'; ++pch)
318 {
319 *(pch - 1) = *pch;
320 }
321
322 if (*pch == '"')
323 *(pch - 1) = ANSI_NULL;
324 }
325
326 return psz;
327}
328
329/*************************************************************************
330 * SheRemoveQuotesW (SHELL32.@)
331 *
332 * ExtractAssociatedIconExW uses this function.
333 */
335WINAPI
337{
338 PWCHAR pch;
339
340 if (*psz == L'"')
341 {
342 for (pch = psz + 1; *pch && *pch != L'"'; ++pch)
343 {
344 *(pch - 1) = *pch;
345 }
346
347 if (*pch == L'"')
348 *(pch - 1) = UNICODE_NULL;
349 }
350
351 return psz;
352}
353
354/*************************************************************************
355 * SHFindComputer [SHELL32.91]
356 *
357 * Invokes the shell search in My Computer. Used in SHFindFiles.
358 * Two parameters are ignored.
359 */
361WINAPI
363{
364 UNREFERENCED_PARAMETER(pidlRoot);
365 UNREFERENCED_PARAMETER(pidlSavedSearch);
366
367 TRACE("%p %p\n", pidlRoot, pidlSavedSearch);
368
369 IContextMenu *pCM;
370 HRESULT hr = CoCreateInstance(CLSID_ShellSearchExt, NULL, CLSCTX_INPROC_SERVER,
371 IID_IContextMenu, (void **)&pCM);
372 if (FAILED(hr))
373 {
374 ERR("0x%08X\n", hr);
375 return hr;
376 }
377
378 CMINVOKECOMMANDINFO InvokeInfo = { sizeof(InvokeInfo) };
379 InvokeInfo.lpParameters = "{996E1EB1-B524-11D1-9120-00A0C98BA67D}";
380 InvokeInfo.nShow = SW_SHOWNORMAL;
381 hr = pCM->InvokeCommand(&InvokeInfo);
382 pCM->Release();
383
384 return SUCCEEDED(hr);
385}
386
387static HRESULT
389 _In_ LONGLONG llValue,
390 _Out_writes_(cchValue) LPWSTR pszValue,
391 _In_ UINT cchValue)
392{
393 WCHAR szBuff[40];
394 UINT ich = 0, ichValue;
395#if (WINVER >= _WIN32_WINNT_VISTA)
396 BOOL bMinus = (llValue < 0);
397
398 if (bMinus)
399 llValue = -llValue;
400#endif
401
402 if (cchValue <= 0)
403 return E_FAIL;
404
405 do
406 {
407 szBuff[ich++] = (WCHAR)(L'0' + (llValue % 10));
408 llValue /= 10;
409 } while (llValue != 0 && ich < _countof(szBuff) - 1);
410
411#if (WINVER >= _WIN32_WINNT_VISTA)
412 if (bMinus && ich < _countof(szBuff))
413 szBuff[ich++] = '-';
414#endif
415
416 for (ichValue = 0; ich > 0 && ichValue < cchValue; ++ichValue)
417 {
418 --ich;
419 pszValue[ichValue] = szBuff[ich];
420 }
421
422 if (ichValue >= cchValue)
423 {
424 pszValue[cchValue - 1] = UNICODE_NULL;
425 return E_FAIL;
426 }
427
428 pszValue[ichValue] = UNICODE_NULL;
429 return S_OK;
430}
431
432static VOID
434 _Out_ NUMBERFMTW *pDest,
435 _In_opt_ const NUMBERFMTW *pSrc,
436 _In_ DWORD dwNumberFlags,
437 _Out_writes_(cchDecimal) LPWSTR pszDecimal,
438 _In_ INT cchDecimal,
439 _Out_writes_(cchThousand) LPWSTR pszThousand,
440 _In_ INT cchThousand)
441{
442 WCHAR szBuff[20];
443
444 if (pSrc)
445 *pDest = *pSrc;
446 else
447 dwNumberFlags = 0;
448
449 if (!(dwNumberFlags & FMT_USE_NUMDIGITS))
450 {
452 pDest->NumDigits = StrToIntW(szBuff);
453 }
454
455 if (!(dwNumberFlags & FMT_USE_LEADZERO))
456 {
458 pDest->LeadingZero = StrToIntW(szBuff);
459 }
460
461 if (!(dwNumberFlags & FMT_USE_GROUPING))
462 {
464 pDest->Grouping = StrToIntW(szBuff);
465 }
466
467 if (!(dwNumberFlags & FMT_USE_DECIMAL))
468 {
469 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, pszDecimal, cchDecimal);
470 pDest->lpDecimalSep = pszDecimal;
471 }
472
473 if (!(dwNumberFlags & FMT_USE_THOUSAND))
474 {
475 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, pszThousand, cchThousand);
476 pDest->lpThousandSep = pszThousand;
477 }
478
479 if (!(dwNumberFlags & FMT_USE_NEGNUMBER))
480 {
482 pDest->NegativeOrder = StrToIntW(szBuff);
483 }
484}
485
486/*************************************************************************
487 * Int64ToString [SHELL32.209]
488 *
489 * @see http://undoc.airesoft.co.uk/shell32.dll/Int64ToString.php
490 */
494 _In_ LONGLONG llValue,
495 _Out_writes_(cchOut) LPWSTR pszOut,
496 _In_ UINT cchOut,
497 _In_ BOOL bUseFormat,
498 _In_opt_ const NUMBERFMTW *pNumberFormat,
499 _In_ DWORD dwNumberFlags)
500{
501 INT ret;
502 NUMBERFMTW NumFormat;
503 WCHAR szValue[80], szDecimalSep[6], szThousandSep[6];
504
505 Int64ToStr(llValue, szValue, _countof(szValue));
506
507 if (bUseFormat)
508 {
509 Int64GetNumFormat(&NumFormat, pNumberFormat, dwNumberFlags,
510 szDecimalSep, _countof(szDecimalSep),
511 szThousandSep, _countof(szThousandSep));
512 ret = GetNumberFormatW(LOCALE_USER_DEFAULT, 0, szValue, &NumFormat, pszOut, cchOut);
513 if (ret)
514 --ret;
515 return ret;
516 }
517
518 if (FAILED(StringCchCopyW(pszOut, cchOut, szValue)))
519 return 0;
520
521 return lstrlenW(pszOut);
522}
523
524/*************************************************************************
525 * LargeIntegerToString [SHELL32.210]
526 *
527 * @see http://undoc.airesoft.co.uk/shell32.dll/LargeIntegerToString.php
528 */
532 _In_ const LARGE_INTEGER *pLargeInt,
533 _Out_writes_(cchOut) LPWSTR pszOut,
534 _In_ UINT cchOut,
535 _In_ BOOL bUseFormat,
536 _In_opt_ const NUMBERFMTW *pNumberFormat,
537 _In_ DWORD dwNumberFlags)
538{
539 return Int64ToString(pLargeInt->QuadPart, pszOut, cchOut, bUseFormat,
540 pNumberFormat, dwNumberFlags);
541}
542
543/*************************************************************************
544 * CopyStreamUI [SHELL32.726]
545 *
546 * Copy a stream to another stream with optional progress display.
547 */
551 _In_ IStream *pSrc,
552 _Out_ IStream *pDst,
553 _Inout_opt_ IProgressDialog *pProgress,
554 _In_opt_ DWORDLONG dwlSize)
555{
556 HRESULT hr = E_FAIL;
557 DWORD cbBuff, cbRead, dwSizeToWrite;
558 DWORDLONG cbDone;
559 LPVOID pBuff;
560 CComHeapPtr<BYTE> pHeapPtr;
561 STATSTG Stat;
562 BYTE abBuff[1024];
563
564 TRACE("(%p, %p, %p, %I64u)\n", pSrc, pDst, pProgress, dwlSize);
565
566 if (dwlSize == 0) // Invalid size?
567 {
568 // Get the stream size
569 ZeroMemory(&Stat, sizeof(Stat));
570 if (FAILED(pSrc->Stat(&Stat, STATFLAG_NONAME)))
571 pProgress = NULL; // No size info. Disable progress
572 else
573 dwlSize = Stat.cbSize.QuadPart;
574 }
575
576 if (!pProgress) // Progress is disabled?
577 {
578 ULARGE_INTEGER uliSize;
579
580 if (dwlSize > 0)
581 uliSize.QuadPart = dwlSize;
582 else
583 uliSize.HighPart = uliSize.LowPart = INVALID_FILE_SIZE;
584
585 return pSrc->CopyTo(pDst, uliSize, NULL, NULL); // One punch
586 }
587
588 // Allocate the buffer if necessary
589 if (dwlSize > 0 && dwlSize <= sizeof(abBuff))
590 {
591 cbBuff = sizeof(abBuff);
592 pBuff = abBuff;
593 }
594 else
595 {
596#define COPY_STREAM_DEFAULT_BUFFER_SIZE 0x4000
598 if (pHeapPtr.AllocateBytes(cbBuff))
599 {
600 pBuff = pHeapPtr;
601 }
602 else // Low memory?
603 {
604 cbBuff = sizeof(abBuff);
605 pBuff = abBuff;
606 }
607#undef COPY_STREAM_DEFAULT_BUFFER_SIZE
608 }
609
610 // Start reading
612 zero.QuadPart = 0;
613 pSrc->Seek(zero, 0, NULL);
614 pDst->Seek(zero, 0, NULL);
615 cbDone = 0;
616 pProgress->SetProgress64(cbDone, dwlSize);
617
618 // Repeat reading and writing until goal
619 for (;;)
620 {
621 hr = pSrc->Read(pBuff, cbBuff, &cbRead);
622 if (FAILED(hr))
623 break;
624
625 // Calculate the size to write
626 if (dwlSize > 0)
627 dwSizeToWrite = (DWORD)min((DWORDLONG)(dwlSize - cbDone), (DWORDLONG)cbRead);
628 else
629 dwSizeToWrite = cbRead;
630
631 if (dwSizeToWrite == 0) // No need to write?
632 {
633 hr = S_OK;
634 break;
635 }
636
637 hr = pDst->Write(pBuff, dwSizeToWrite, NULL);
638 if (hr != S_OK)
639 break;
640
641 cbDone += dwSizeToWrite;
642
643 if (pProgress->HasUserCancelled()) // Cancelled?
644 {
646 break;
647 }
648 pProgress->SetProgress64(cbDone, dwlSize);
649
650 if (dwlSize > 0 && cbDone >= dwlSize) // Reached the goal?
651 {
652 hr = S_OK;
653 break;
654 }
655 }
656
657 return hr;
658}
659
660/*************************************************************************
661 * SHOpenPropSheetA [SHELL32.707]
662 *
663 * @see https://learn.microsoft.com/en-us/windows/win32/api/shlobj/nf-shlobj-shopenpropsheeta
664 */
668 _In_opt_ LPCSTR pszCaption,
669 _In_opt_ HKEY *ahKeys,
670 _In_ UINT cKeys,
671 _In_ const CLSID *pclsidDefault,
672 _In_ IDataObject *pDataObject,
673 _In_opt_ IShellBrowser *pShellBrowser,
674 _In_opt_ LPCSTR pszStartPage)
675{
676 CStringW strStartPageW, strCaptionW;
677 LPCWSTR pszCaptionW = NULL, pszStartPageW = NULL;
678
679 TRACE("(%s, %p, %u, %p, %p, %p, %s)", debugstr_a(pszCaption), ahKeys, cKeys, pclsidDefault,
680 pDataObject, pShellBrowser, debugstr_a(pszStartPage));
681
682 if (pszCaption)
683 {
684 strStartPageW = pszCaption;
685 pszCaptionW = strCaptionW;
686 }
687
688 if (pszStartPage)
689 {
690 strStartPageW = pszStartPage;
691 pszStartPageW = strStartPageW;
692 }
693
694 return SHOpenPropSheetW(pszCaptionW, ahKeys, cKeys, pclsidDefault,
695 pDataObject, pShellBrowser, pszStartPageW);
696}
697
698/*************************************************************************
699 * Activate_RunDLL [SHELL32.105]
700 *
701 * Unlocks the foreground window and allows the shell window to become the
702 * foreground window. Every parameter is unused.
703 */
707 _In_ HWND hwnd,
710 _In_ INT cmdshow)
711{
712 DWORD dwProcessID;
713
717 UNREFERENCED_PARAMETER(cmdshow);
718
719 TRACE("(%p, %p, %s, %d)\n", hwnd, hinst, debugstr_w(cmdline), cmdline);
720
722 return AllowSetForegroundWindow(dwProcessID);
723}
724
725/*************************************************************************
726 * SHStartNetConnectionDialogA (SHELL32.12)
727 *
728 * @see https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shstartnetconnectiondialoga
729 */
733 _In_ HWND hwnd,
734 _In_ LPCSTR pszRemoteName,
735 _In_ DWORD dwType)
736{
737 LPCWSTR pszRemoteNameW = NULL;
738 CStringW strRemoteNameW;
739
740 TRACE("(%p, %s, %lu)\n", hwnd, debugstr_a(pszRemoteName), dwType);
741
742 if (pszRemoteName)
743 {
744 strRemoteNameW = pszRemoteName;
745 pszRemoteNameW = strRemoteNameW;
746 }
747
748 return SHStartNetConnectionDialogW(hwnd, pszRemoteNameW, dwType);
749}
750
751/*************************************************************************
752 * Helper functions for PathIsEqualOrSubFolder
753 */
754
755static INT
757 _In_ LPCWSTR lpszPath1,
758 _In_ LPCWSTR lpszPath2,
759 _Out_ CStringW& strPath)
760{
761 SIZE_T cchPath1 = wcslen(lpszPath1);
762 SIZE_T cchPath2 = wcslen(lpszPath2);
763 LPWSTR lpszPath = strPath.GetBuffer((INT)max(cchPath1, cchPath2) + 16);
764 INT ret = PathCommonPrefixW(lpszPath1, lpszPath2, lpszPath);
765 strPath.ReleaseBuffer();
766 return ret;
767}
768
771
772static HRESULT
774 _In_ LPCITEMIDLIST pidl,
775 _Out_ CStringW& strPath)
776{
777 HRESULT hr;
778
779 for (UINT cchPath = MAX_PATH;; cchPath *= 2)
780 {
781 LPWSTR lpszPath = strPath.GetBuffer(cchPath);
782 if (!lpszPath)
783 return E_OUTOFMEMORY;
784
785 hr = SHGetPathCchFromIDListW(pidl, lpszPath, cchPath);
786 strPath.ReleaseBuffer();
787
789 break;
790
791 if (cchPath >= MAXUINT / 2)
792 {
793 hr = E_FAIL;
794 break;
795 }
796 }
797
798 if (FAILED(hr))
799 strPath.Empty();
800
801 return hr;
802}
803
804static HRESULT
806 _In_ HWND hwndOwner,
807 _Out_ CStringW& strPath,
808 _In_ INT nCSIDL,
810{
811 LPITEMIDLIST pidl;
812 HRESULT hr = SHGetSpecialFolderLocation(hwndOwner, nCSIDL, &pidl);
813 if (SUCCEEDED(hr))
814 {
815 hr = DynamicSHGetPathFromIDListW(pidl, strPath);
816 CoTaskMemFree(pidl);
817 }
818
819 if (FAILED(hr))
820 strPath.Empty();
821 else if (bCreate)
822 CreateDirectoryW(strPath, NULL);
823
824 return hr;
825}
826
827static VOID
829 _Out_ CStringW& strPath)
830{
831 INT nLength = strPath.GetLength();
832 if (nLength > 0 && strPath[nLength - 1] == L'\\')
833 strPath = strPath.Left(nLength - 1);
834}
835
836/*************************************************************************
837 * PathIsEqualOrSubFolder (SHELL32.755)
838 */
842 _In_ LPCWSTR pszPath1OrCSIDL,
843 _In_ LPCWSTR pszPath2)
844{
845 CStringW strCommon, strPath1;
846
847 TRACE("(%s %s)\n", debugstr_w(pszPath1OrCSIDL), debugstr_w(pszPath2));
848
849 if (IS_INTRESOURCE(pszPath1OrCSIDL))
850 {
852 NULL, strPath1, LOWORD(pszPath1OrCSIDL) | CSIDL_FLAG_DONT_VERIFY, FALSE);
853 }
854 else
855 {
856 strPath1 = pszPath1OrCSIDL;
857 }
858
860
861 if (!DynamicPathCommonPrefixW(strPath1, pszPath2, strCommon))
862 return FALSE;
863
864 return strPath1.CompareNoCase(strCommon) == 0;
865}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
void shell(int argc, const char *argv[])
Definition: cmds.c:1231
#define EXTERN_C
Definition: basetyps.h:12
#define ERR(fmt,...)
Definition: debug.h:110
int CompareNoCase(_In_z_ PCXSTR psz) const
Definition: cstringt.h:743
bool AllocateBytes(_In_ size_t nBytes)
Definition: atlalloc.h:127
LPARAM lParam
Definition: combotst.c:139
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:374
BOOL WINAPI GetTokenInformation(HANDLE TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, LPVOID TokenInformation, DWORD TokenInformationLength, PDWORD ReturnLength)
Definition: security.c:411
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
BOOL WINAPI OpenThreadToken(HANDLE ThreadHandle, DWORD DesiredAccess, BOOL OpenAsSelf, HANDLE *TokenHandle)
Definition: security.c:336
INT WINAPI StrToIntW(LPCWSTR lpString)
Definition: string.c:411
#define CloseHandle
Definition: compat.h:739
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define GetCurrentProcess()
Definition: compat.h:759
#define MAX_PATH
Definition: compat.h:34
#define lstrlenW
Definition: compat.h:750
static DWORD DWORD * dwLength
Definition: fusion.c:86
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: loader.c:288
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
EXTERN_C WORD WINAPI ExtractIconResInfoW(_In_ HANDLE hHandle, _In_ LPCWSTR lpFileName, _In_ WORD wIndex, _Out_ LPWORD lpSize, _Out_ LPHANDLE lpIcon)
Definition: stubs.cpp:889
EXTERN_C HRESULT WINAPI SHSetFolderPathW(_In_ INT csidl, _In_ HANDLE hToken, _In_ DWORD dwFlags, _In_ LPCWSTR pszPath)
Definition: stubs.cpp:964
EXTERN_C HRESULT WINAPI SHStartNetConnectionDialogW(_In_ HWND hwnd, _In_ LPCWSTR pszRemoteName, _In_ DWORD dwType)
Definition: stubs.cpp:696
BOOL WINAPI SHOpenPropSheetW(_In_opt_ LPCWSTR pszCaption, _In_opt_ HKEY *ahKeys, _In_ UINT cKeys, _In_ const CLSID *pclsidDefault, _In_ IDataObject *pDataObject, _In_opt_ IShellBrowser *pShellBrowser, _In_opt_ LPCWSTR pszStartPage)
Definition: stubs.cpp:197
EXTERN_C BOOL WINAPI PathIsSlowW(_In_ LPCWSTR pszFile, _In_ DWORD dwAttr)
Definition: stubs.cpp:1012
EXTERN_C BOOL WINAPI SHOpenPropSheetA(_In_opt_ LPCSTR pszCaption, _In_opt_ HKEY *ahKeys, _In_ UINT cKeys, _In_ const CLSID *pclsidDefault, _In_ IDataObject *pDataObject, _In_opt_ IShellBrowser *pShellBrowser, _In_opt_ LPCSTR pszStartPage)
Definition: utils.cpp:667
BOOL WINAPI IsSuspendAllowed(VOID)
Definition: utils.cpp:248
EXTERN_C HRESULT WINAPI SHGetPathCchFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath, SIZE_T cchPathMax)
static VOID DynamicPathRemoveBackslashW(_Out_ CStringW &strPath)
Definition: utils.cpp:828
EXTERN_C WORD WINAPI ExtractIconResInfoA(_In_ HANDLE hHandle, _In_ LPCSTR lpFileName, _In_ WORD wIndex, _Out_ LPWORD lpSize, _Out_ LPHANDLE lpIcon)
Definition: utils.cpp:73
EXTERN_C BOOL WINAPI PathIsEqualOrSubFolder(_In_ LPCWSTR pszPath1OrCSIDL, _In_ LPCWSTR pszPath2)
Definition: utils.cpp:841
EXTERN_C DWORD WINAPI SHGetUserSessionId(_In_opt_ HANDLE hToken)
Definition: utils.cpp:114
#define COPY_STREAM_DEFAULT_BUFFER_SIZE
static VOID Int64GetNumFormat(_Out_ NUMBERFMTW *pDest, _In_opt_ const NUMBERFMTW *pSrc, _In_ DWORD dwNumberFlags, _Out_writes_(cchDecimal) LPWSTR pszDecimal, _In_ INT cchDecimal, _Out_writes_(cchThousand) LPWSTR pszThousand, _In_ INT cchThousand)
Definition: utils.cpp:433
EXTERN_C BOOL WINAPI SHTestTokenPrivilegeW(_In_opt_ HANDLE hToken, _In_ LPCWSTR lpName)
Definition: utils.cpp:184
EXTERN_C HRESULT WINAPI SHInvokePrivilegedFunctionW(_In_ LPCWSTR pszName, _In_ PRIVILEGED_FUNCTION fn, _In_opt_ LPARAM lParam)
Definition: utils.cpp:141
EXTERN_C LPWSTR WINAPI ShortSizeFormatW(_In_ DWORD dwNumber, _Out_writes_(0x8FFF) LPWSTR pszBuffer)
Definition: utils.cpp:94
EXTERN_C LPSTR WINAPI SheRemoveQuotesA(LPSTR psz)
Definition: utils.cpp:311
static INT DynamicPathCommonPrefixW(_In_ LPCWSTR lpszPath1, _In_ LPCWSTR lpszPath2, _Out_ CStringW &strPath)
Definition: utils.cpp:756
static HRESULT DynamicSHGetPathFromIDListW(_In_ LPCITEMIDLIST pidl, _Out_ CStringW &strPath)
Definition: utils.cpp:773
EXTERN_C INT WINAPI Int64ToString(_In_ LONGLONG llValue, _Out_writes_(cchOut) LPWSTR pszOut, _In_ UINT cchOut, _In_ BOOL bUseFormat, _In_opt_ const NUMBERFMTW *pNumberFormat, _In_ DWORD dwNumberFlags)
Definition: utils.cpp:493
EXTERN_C BOOL WINAPI Activate_RunDLL(_In_ HWND hwnd, _In_ HINSTANCE hinst, _In_ LPCWSTR cmdline, _In_ INT cmdshow)
Definition: utils.cpp:706
EXTERN_C BOOL WINAPI PathIsSlowA(_In_ LPCSTR pszFile, _In_ DWORD dwAttr)
Definition: utils.cpp:59
EXTERN_C INT WINAPI LargeIntegerToString(_In_ const LARGE_INTEGER *pLargeInt, _Out_writes_(cchOut) LPWSTR pszOut, _In_ UINT cchOut, _In_ BOOL bUseFormat, _In_opt_ const NUMBERFMTW *pNumberFormat, _In_ DWORD dwNumberFlags)
Definition: utils.cpp:531
EXTERN_C HINSTANCE WINAPI SHGetShellStyleHInstance(VOID)
Definition: utils.cpp:259
EXTERN_C HRESULT WINAPI CopyStreamUI(_In_ IStream *pSrc, _Out_ IStream *pDst, _Inout_opt_ IProgressDialog *pProgress, _In_opt_ DWORDLONG dwlSize)
Definition: utils.cpp:550
static BOOL OpenEffectiveToken(_In_ DWORD DesiredAccess, _Out_ HANDLE *phToken)
Definition: utils.cpp:13
EXTERN_C BOOL WINAPI SHFindComputer(LPCITEMIDLIST pidlRoot, LPCITEMIDLIST pidlSavedSearch)
Definition: utils.cpp:362
static HRESULT Int64ToStr(_In_ LONGLONG llValue, _Out_writes_(cchValue) LPWSTR pszValue, _In_ UINT cchValue)
Definition: utils.cpp:388
EXTERN_C LPWSTR WINAPI SheRemoveQuotesW(LPWSTR psz)
Definition: utils.cpp:336
EXTERN_C HRESULT WINAPI SHCreatePropertyBag(_In_ REFIID riid, _Out_ void **ppvObj)
Definition: utils.cpp:301
EXTERN_C HRESULT WINAPI SHSetFolderPathA(_In_ INT csidl, _In_ HANDLE hToken, _In_ DWORD dwFlags, _In_ LPCSTR pszPath)
Definition: utils.cpp:41
BOOL IsShutdownAllowed(VOID)
Definition: utils.cpp:240
EXTERN_C HRESULT WINAPI SHStartNetConnectionDialogA(_In_ HWND hwnd, _In_ LPCSTR pszRemoteName, _In_ DWORD dwType)
Definition: utils.cpp:732
EXTERN_C BOOL WINAPI SHOpenEffectiveToken(_Out_ LPHANDLE phToken)
Definition: utils.cpp:105
static HRESULT DynamicSHGetSpecialFolderPathW(_In_ HWND hwndOwner, _Out_ CStringW &strPath, _In_ INT nCSIDL, _In_ BOOL bCreate)
Definition: utils.cpp:805
HRESULT WINAPI SHGetSpecialFolderLocation(HWND hwndOwner, INT nFolder, LPITEMIDLIST *ppidl)
Definition: shellpath.c:3194
int WINAPI PathCommonPrefixW(LPCWSTR lpszFile1, LPCWSTR lpszFile2, LPWSTR achPath)
Definition: path.c:2806
BOOL WINAPI PathRemoveFileSpecW(LPWSTR lpszPath)
Definition: path.c:629
LPWSTR WINAPI StrFormatByteSizeW(LONGLONG llBytes, LPWSTR lpszDest, UINT cchMax)
Definition: string.c:2380
HRESULT WINAPI GetCurrentThemeName(LPWSTR pszThemeFileName, int dwMaxNameChars, LPWSTR pszColorBuff, int cchMaxColorChars, LPWSTR pszSizeBuff, int cchMaxSizeChars)
Definition: system.c:894
static const WCHAR szColorName[]
Definition: system.c:40
HINSTANCE hInst
Definition: dxdiag.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
REFIID riid
Definition: atlbase.h:39
HRESULT InvokeCommand([in] LPCMINVOKECOMMANDINFO lpici)
ULONG Release()
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
unsigned long long DWORDLONG
Definition: intsafe.h:93
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_a
Definition: kernel32.h:31
#define debugstr_w
Definition: kernel32.h:32
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: lang.c:1108
INT WINAPI GetNumberFormatW(LCID lcid, DWORD dwFlags, LPCWSTR lpszValue, const NUMBERFMTW *lpFormat, LPWSTR lpNumberStr, int cchOut)
Definition: lcformat.c:1212
#define Stat
Definition: syshdrs.h:78
#define pch(ap)
Definition: match.c:418
LPCWSTR szPath
Definition: env.c:37
static HINSTANCE hinst
Definition: edit.c:551
#define min(a, b)
Definition: monoChain.cc:55
#define _Out_writes_(size)
Definition: ms_sal.h:348
#define _Inout_opt_
Definition: ms_sal.h:379
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
#define _In_opt_
Definition: ms_sal.h:309
unsigned int UINT
Definition: ndis.h:50
#define DWORD
Definition: nt_native.h:44
#define LOCALE_USER_DEFAULT
#define UNICODE_NULL
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define ANSI_NULL
#define L(x)
Definition: ntvdm.h:50
#define STGM_READWRITE
Definition: objbase.h:919
#define LOWORD(l)
Definition: pedump.c:82
BOOLEAN WINAPI IsPwrSuspendAllowed(VOID)
Definition: powrprof.c:488
EXTERN_C HRESULT WINAPI SHCreatePropertyBagOnMemory(_In_ DWORD dwMode, _In_ REFIID riid, _Out_ void **ppvObj)
Definition: propbag.cpp:254
#define REFIID
Definition: guiddef.h:118
int zero
Definition: sehframes.cpp:29
HRESULT hr
Definition: shlfolder.c:183
_In_ int _In_ BOOL bCreate
Definition: shlobj.h:1511
#define CSIDL_FLAG_DONT_VERIFY
Definition: shlobj.h:2152
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
#define _countof(array)
Definition: sndvol32.h:68
#define TRACE(s)
Definition: solgame.cpp:4
TCHAR * cmdline
Definition: stretchblt.cpp:32
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
$ULONG PrivilegeCount
Definition: setypes.h:1023
LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]
Definition: setypes.h:1024
$ULONG LowPart
Definition: ntbasedef.h:569
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
$ULONG HighPart
Definition: ntbasedef.h:570
#define max(a, b)
Definition: svc.c:63
uint16_t * LPWORD
Definition: typedefs.h:56
int64_t LONGLONG
Definition: typedefs.h:68
ULONG_PTR SIZE_T
Definition: typedefs.h:80
int32_t INT
Definition: typedefs.h:58
uint16_t * PWCHAR
Definition: typedefs.h:56
char * PCHAR
Definition: typedefs.h:51
#define FMT_USE_THOUSAND
Definition: undocshell.h:687
#define FMT_USE_GROUPING
Definition: undocshell.h:685
#define FMT_USE_NUMDIGITS
Definition: undocshell.h:683
#define FMT_USE_NEGNUMBER
Definition: undocshell.h:688
#define FMT_USE_LEADZERO
Definition: undocshell.h:684
HRESULT(CALLBACK * PRIVILEGED_FUNCTION)(LPARAM lParam)
Definition: undocshell.h:716
#define FMT_USE_DECIMAL
Definition: undocshell.h:686
int ret
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159
HWND WINAPI GetShellWindow(VOID)
Definition: desktop.c:651
BOOL WINAPI AllowSetForegroundWindow(DWORD dwProcessId)
Definition: window.c:49
#define ZeroMemory
Definition: winbase.h:1712
_In_opt_ LPSTR _In_opt_ LPSTR _In_ DWORD _In_ DWORD _Out_opt_ PHANDLE phToken
Definition: winbase.h:2715
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ LPCSTR lpFileName
Definition: winbase.h:3071
HANDLE WINAPI GetCurrentThread(void)
Definition: proc.c:1148
#define LPTR
Definition: winbase.h:381
#define LOAD_LIBRARY_AS_DATAFILE
Definition: winbase.h:342
_In_ LPCSTR lpName
Definition: winbase.h:2789
DWORD WINAPI GetWindowThreadProcessId(HWND hWnd, PDWORD lpdwProcessId)
#define INVALID_FILE_SIZE
Definition: winbase.h:548
_In_ DWORD nLength
Definition: wincon.h:473
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
#define WINAPI
Definition: msvc.h:6
#define E_NOT_SUFFICIENT_BUFFER
Definition: winerror.h:2345
#define ERROR_CANCELLED
Definition: winerror.h:726
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#define ERROR_NO_TOKEN
Definition: winerror.h:587
#define LOCALE_SGROUPING
Definition: winnls.h:44
#define LOCALE_SDECIMAL
Definition: winnls.h:42
#define LOCALE_IDIGITS
Definition: winnls.h:45
#define LOCALE_STHOUSAND
Definition: winnls.h:43
#define LOCALE_INEGNUMBER
Definition: winnls.h:47
#define LOCALE_ILZERO
Definition: winnls.h:46
#define SE_SHUTDOWN_NAME
Definition: winnt_old.h:384
#define SW_SHOWNORMAL
Definition: winuser.h:769
#define IS_INTRESOURCE(i)
Definition: winuser.h:580
#define RtlEqualLuid(Luid1, Luid2)
Definition: rtlfuncs.h:301
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:930
#define TOKEN_QUERY
Definition: setypes.h:928
@ TokenPrivileges
Definition: setypes.h:968
@ TokenSessionId
Definition: setypes.h:977
struct _TOKEN_PRIVILEGES * PTOKEN_PRIVILEGES
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
const char * LPCSTR
Definition: xmlstorage.h:183
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
unsigned char BYTE
Definition: xxhash.c:193