ReactOS 0.4.17-dev-1190-g4c812f4
COpenWithMenu.cpp File Reference
#include "precomp.h"
Include dependency graph for COpenWithMenu.cpp:

Go to the source code of this file.

Classes

class  COpenWithList
 
struct  COpenWithList::SApp
 
struct  COpenWithList::_LANGANDCODEPAGE
 
class  COpenWithDialog
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (shell)
 
EXTERN_C BOOL PathIsExeW (LPCWSTR lpszPath)
 
static SIZE_T PathGetAppFromCommandLine (LPCWSTR pszIn, LPWSTR pszOut, SIZE_T cchMax)
 
HRESULT SHELL32_GetDllFromRundll32CommandLine (LPCWSTR pszCmd, LPWSTR pszOut, SIZE_T cchMax)
 
static HRESULT SH32_EvaluateValidExecApp (_Inout_ PWSTR pszCmd, _In_ SIZE_T cchMax)
 
HRESULT SH32_InvokeOpenWith (_In_ PCWSTR pszPath, _In_ LPCMINVOKECOMMANDINFO pici, _Out_ HANDLE *phProcess)
 
HRESULT WINAPI SHOpenWithDialog (HWND hwndParent, const OPENASINFO *poainfo)
 

Variables

static const CMVERBMAP g_VerbMap []
 

Function Documentation

◆ PathGetAppFromCommandLine()

static SIZE_T PathGetAppFromCommandLine ( LPCWSTR  pszIn,
LPWSTR  pszOut,
SIZE_T  cchMax 
)
static

Definition at line 34 of file COpenWithMenu.cpp.

35{
36 SIZE_T count = 0;
37 WCHAR stop = ' ';
38 if (pszIn[0] == '"')
39 stop = *(pszIn++);
40
41 for (LPCWSTR pwszSrc = pszIn; *pwszSrc && *pwszSrc != stop; ++pwszSrc)
42 {
43 if (++count >= cchMax)
44 return 0;
45 *(pszOut++) = *pwszSrc;
46 }
47 *pszOut = UNICODE_NULL;
48 return count;
49}
UINT cchMax
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define UNICODE_NULL
short WCHAR
Definition: pedump.c:58
const uint16_t * LPCWSTR
Definition: typedefs.h:57
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by COpenWithList::GetPathFromCmd(), SH32_EvaluateValidExecApp(), and SHELL32_GetDllFromRundll32CommandLine().

◆ PathIsExeW()

◆ SH32_EvaluateValidExecApp()

static HRESULT SH32_EvaluateValidExecApp ( _Inout_ PWSTR  pszCmd,
_In_ SIZE_T  cchMax 
)
static

Definition at line 84 of file COpenWithMenu.cpp.

85{
86 // FIXME: SHEvaluateSystemCommandTemplate is not implemented yet, using a minimal version.
87 if (!PathGetAppFromCommandLine(pszCmd, pszCmd, cchMax))
88 return E_FAIL;
89
91 WCHAR szCurrDir[MAX_PATH];
92 LPCWSTR pszDirsArr[2] = { szCurrDir, NULL }, *ppszDirs = NULL;
93 if (GetCurrentDirectoryW(_countof(szCurrDir), szCurrDir))
94 ppszDirs = pszDirsArr;
95 if (PathResolveW(pszCmd, ppszDirs, fPRF | (ppszDirs ? PRF_FIRSTDIRDEF : 0)))
96 return S_OK;
97 return E_FAIL;
98}
static SIZE_T PathGetAppFromCommandLine(LPCWSTR pszIn, LPWSTR pszOut, SIZE_T cchMax)
#define PRF_VERIFYEXISTS
Definition: PathResolve.cpp:38
#define PRF_TRYPROGRAMEXTENSIONS
Definition: PathResolve.cpp:40
#define PRF_FIRSTDIRDEF
Definition: PathResolve.cpp:41
#define PRF_DONTFINDLNK
Definition: PathResolve.cpp:42
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:756
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI PathResolveW(WCHAR *path, const WCHAR **dirs, DWORD flags)
Definition: shellpath.c:1447
unsigned int UINT
Definition: sysinfo.c:13
#define S_OK
Definition: intsafe.h:52
#define _countof(array)
Definition: sndvol32.h:70

Referenced by SH32_InvokeOpenWith().

◆ SH32_InvokeOpenWith()

HRESULT SH32_InvokeOpenWith ( _In_ PCWSTR  pszPath,
_In_ LPCMINVOKECOMMANDINFO  pici,
_Out_ HANDLE *  phProcess 
)

Definition at line 100 of file COpenWithMenu.cpp.

101{
102 if (!pszPath || !pici)
104
106 SHELLEXECUTEINFOW sei = { sizeof(sei), CmicFlagsToSeeFlags(pici->fMask), pici->hwnd };
108 sei.lpFile = pszPath;
109 sei.nShow = pici->nShow;
110 if (phProcess)
111 {
113 sei.hProcess = NULL;
114 }
115
116 if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, L"Unknown", 0, KEY_READ, &sei.hkeyClass))
117 {
118 // Use the internal dialog only if HKCR\Unknown\shell\openas\command exists but is invalid.
119 WCHAR szCmd[MAX_PATH * 2];
120 DWORD cch = _countof(szCmd);
123 ASSOCSTR_COMMAND, sei.hkeyClass, NULL, szCmd, &cch);
124 if (SUCCEEDED(hr) && FAILED(SH32_EvaluateValidExecApp(szCmd, _countof(szCmd))))
125 {
127 hr = SHOpenWithDialog(sei.hwnd, &info);
128 }
129 else
130 {
132 }
134 }
135 else if (!(pici->fMask & CMIC_MASK_FLAG_NO_UI))
136 {
137 SHELL_ErrorBox(sei.hwnd, hr);
138 }
139
140 if (phProcess)
141 *phProcess = sei.hProcess;
142 return hr;
143}
HRESULT WINAPI SHOpenWithDialog(HWND hwndParent, const OPENASINFO *poainfo)
static HRESULT SH32_EvaluateValidExecApp(_Inout_ PWSTR pszCmd, _In_ SIZE_T cchMax)
#define RegCloseKey(hKey)
Definition: registry.h:49
HRESULT hr
Definition: delayimp.cpp:582
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
HRESULT WINAPI AssocQueryStringByKeyW(ASSOCF cfFlags, ASSOCSTR str, HKEY hkAssoc, LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut)
Definition: assoc.c:672
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define HResultFromWin32
Definition: loader.cpp:14
#define KEY_READ
Definition: nt_native.h:1026
@ ASSOCSTR_COMMAND
Definition: shlwapi.h:886
@ ASSOCF_NOFIXUPS
Definition: shlwapi.h:868
@ ASSOCF_IGNOREBASECLASS
Definition: shlwapi.h:869
@ ASSOCF_INIT_IGNOREUNKNOWN
Definition: shlwapi.h:870
@ ASSOCF_NOTRUNCATE
Definition: shlwapi.h:865
_In_ UINT _In_ UINT cch
Definition: shellapi.h:428
#define SEE_MASK_CLASSKEY
Definition: shellapi.h:26
#define SEE_MASK_NOCLOSEPROCESS
Definition: shellapi.h:33
#define SEE_MASK_NOZONECHECKS
Definition: shellapi.h:48
#define SHELL_ErrorBox
Definition: shellutils.h:126
BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExW(LPSHELLEXECUTEINFOW sei)
Definition: shlexec.cpp:2738
@ OAIF_EXEC
Definition: shlobj.h:2729
@ OAIF_REGISTER_EXT
Definition: shlobj.h:2728
@ OAIF_ALLOW_REGISTRATION
Definition: shlobj.h:2727
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_NO_ASSOCIATION
Definition: winerror.h:1001
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10

Referenced by COpenWithMenu::InvokeCommand(), and InvokeOpenWith().

◆ SHELL32_GetDllFromRundll32CommandLine()

HRESULT SHELL32_GetDllFromRundll32CommandLine ( LPCWSTR  pszCmd,
LPWSTR  pszOut,
SIZE_T  cchMax 
)

Definition at line 51 of file COpenWithMenu.cpp.

52{
53 WCHAR szDll[MAX_PATH + 100];
54 if (!PathGetAppFromCommandLine(pszCmd, szDll, _countof(szDll)))
56
57 PWSTR pszName = PathFindFileNameW(szDll);
58 if (_wcsicmp(pszName, L"rundll32") && _wcsicmp(pszName, L"rundll32.exe"))
59 return E_UNEXPECTED;
60
61 PCWSTR pszDllStart = pszCmd + (pszName - szDll) + lstrlenW(pszName);
62
63 if (*pszDllStart == '\"')
64 ++pszDllStart; // Skip possible end quote of ..\rundll32.exe" foo.dll,func
65 while (*pszDllStart <= ' ' && *pszDllStart)
66 ++pszDllStart;
67 if (PathGetAppFromCommandLine(pszDllStart, szDll, _countof(szDll)))
68 {
69 BOOL quoted = *pszDllStart == '\"';
70 PWSTR pszComma = szDll + lstrlenW(szDll);
71 while (!quoted && pszComma > szDll && *pszComma != ',' && *pszComma != '\\' && *pszComma != '/')
72 --pszComma;
73 SIZE_T cch = pszComma - szDll;
74 if (cch <= cchMax && (quoted || *pszComma == ','))
75 {
76 *pszComma = UNICODE_NULL;
77 lstrcpynW(pszOut, szDll, cchMax);
78 return S_OK;
79 }
80 }
82}
#define lstrcpynW
Definition: compat.h:738
#define lstrlenW
Definition: compat.h:750
WCHAR *WINAPI PathFindFileNameW(const WCHAR *path)
Definition: path.c:1677
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:164
unsigned int BOOL
Definition: ntddk_ex.h:94
uint16_t * PWSTR
Definition: typedefs.h:56
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:307
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define E_UNEXPECTED
Definition: winerror.h:3528

Referenced by COpenWithList::GetPathFromCmd(), and CFileDefExt::InitOpensWithField().

◆ SHOpenWithDialog()

HRESULT WINAPI SHOpenWithDialog ( HWND  hwndParent,
const OPENASINFO *  poainfo 
)

Definition at line 1578 of file COpenWithMenu.cpp.

1579{
1580 INT_PTR ret;
1581
1582 TRACE("SHOpenWithDialog hwndParent %p poainfo %p\n", hwndParent, poainfo);
1583
1585
1586 if (poainfo->pcszClass == NULL && poainfo->pcszFile == NULL)
1587 return E_FAIL;
1588
1589 COpenWithDialog pDialog(poainfo);
1590
1591 if (pDialog.IsNoOpen(hwndParent))
1592 return S_OK;
1593
1596
1597 if (ret == (INT_PTR)-1)
1598 {
1599 ERR("Failed to create dialog: %u\n", GetLastError());
1600 return E_FAIL;
1601 }
1602
1603 return S_OK;
1604}
#define shell32_hInstance
#define ERR(fmt,...)
Definition: precomp.h:57
static INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
VOID WINAPI InitCommonControls(void)
Definition: commctrl.c:874
static HWND hwndParent
Definition: cryptui.c:299
return ret
Definition: mutex.c:147
LONG_PTR LPARAM
Definition: minwindef.h:175
#define MAKEINTRESOURCE(i)
Definition: ntverrsrc.c:25
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
#define IDD_OPEN_WITH
Definition: shresdef.h:557
#define TRACE(s)
Definition: solgame.cpp:4
LPCWSTR pcszFile
Definition: shlobj.h:2740
LPCWSTR pcszClass
Definition: shlobj.h:2741
int32_t INT_PTR
Definition: typedefs.h:64

Referenced by FolderOptionsFileTypesDlg(), CFileDefExt::GeneralPageProc(), OpenAs_RunDLLW(), and SH32_InvokeOpenWith().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( shell  )

Variable Documentation

◆ g_VerbMap

const CMVERBMAP g_VerbMap[]
static
Initial value:
=
{
{ "openas", 0 },
{ NULL }
}

Definition at line 1377 of file COpenWithMenu.cpp.