ReactOS 0.4.16-dev-1308-gbf734eb
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
ULONG_PTR SIZE_T
Definition: typedefs.h:80
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

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

◆ PathIsExeW()

EXTERN_C BOOL PathIsExeW ( LPCWSTR  lpszPath)

Definition at line 539 of file shellpath.c.

540{
541 LPCWSTR lpszExtension = PathGetExtensionW(lpszPath);
542 int i;
543 static const WCHAR lpszExtensions[][4] =
544 {L"exe", L"com", L"pif", L"cmd", L"bat", L"scf", L"scr", L"" };
545
546 TRACE("path=%s\n",debugstr_w(lpszPath));
547
548 for(i=0; lpszExtensions[i][0]; i++)
549 if (!wcsicmp(lpszExtension,lpszExtensions[i])) return TRUE;
550
551 return FALSE;
552}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define wcsicmp
Definition: compat.h:15
static LPWSTR PathGetExtensionW(LPCWSTR lpszPath)
Definition: shellpath.c:434
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define debugstr_w
Definition: kernel32.h:32
#define L(x)
Definition: ntvdm.h:50
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by COpenWithDialog::Init(), CFileDefExt::InitGeneralPage(), and COpenWithMenu::Initialize().

◆ 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(_Inout_ LPWSTR path, _Inout_opt_ LPCWSTR *dirs, _In_ DWORD flags)
Definition: shellpath.c:1032
#define S_OK
Definition: intsafe.h:52
unsigned int UINT
Definition: ndis.h:50
#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
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:537
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
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:202
#define KEY_READ
Definition: nt_native.h:1023
#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:2552
HRESULT hr
Definition: shlfolder.c:183
@ OAIF_EXEC
Definition: shlobj.h:2690
@ OAIF_REGISTER_EXT
Definition: shlobj.h:2689
@ OAIF_ALLOW_REGISTRATION
Definition: shlobj.h:2688
@ ASSOCSTR_COMMAND
Definition: shlwapi.h:612
@ ASSOCF_NOFIXUPS
Definition: shlwapi.h:600
@ ASSOCF_IGNOREBASECLASS
Definition: shlwapi.h:601
@ ASSOCF_INIT_IGNOREUNKNOWN
Definition: shlwapi.h:602
@ ASSOCF_NOTRUNCATE
Definition: shlwapi.h:597
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_NO_ASSOCIATION
Definition: winerror.h:677
#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:1644
unsigned int BOOL
Definition: ntddk_ex.h:94
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
uint16_t * PWSTR
Definition: typedefs.h:56
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
#define E_UNEXPECTED
Definition: winerror.h:2456
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92

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

◆ SHOpenWithDialog()

HRESULT WINAPI SHOpenWithDialog ( HWND  hwndParent,
const OPENASINFO poainfo 
)

Definition at line 1572 of file COpenWithMenu.cpp.

1573{
1574 INT_PTR ret;
1575
1576 TRACE("SHOpenWithDialog hwndParent %p poainfo %p\n", hwndParent, poainfo);
1577
1579
1580 if (poainfo->pcszClass == NULL && poainfo->pcszFile == NULL)
1581 return E_FAIL;
1582
1583 COpenWithDialog pDialog(poainfo);
1584
1585 if (pDialog.IsNoOpen(hwndParent))
1586 return S_OK;
1587
1590
1591 if (ret == (INT_PTR)-1)
1592 {
1593 ERR("Failed to create dialog: %u\n", GetLastError());
1594 return E_FAIL;
1595 }
1596
1597 return S_OK;
1598}
#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:300
#define MAKEINTRESOURCE(i)
Definition: ntverrsrc.c:25
#define IDD_OPEN_WITH
Definition: shresdef.h:548
LPCWSTR pcszFile
Definition: shlobj.h:2701
LPCWSTR pcszClass
Definition: shlobj.h:2702
int32_t INT_PTR
Definition: typedefs.h:64
int ret
LONG_PTR LPARAM
Definition: windef.h:208
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)

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 1371 of file COpenWithMenu.cpp.