ReactOS 0.4.16-dev-1521-gb8f1da6
shlextdbg.cpp File Reference
#include <windows.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <atlbase.h>
#include <atlcom.h>
#include <atlstr.h>
#include <atlsimpcoll.h>
#include <conio.h>
#include <shellutils.h>
#include <shlwapi_undoc.h>
Include dependency graph for shlextdbg.cpp:

Go to the source code of this file.

Classes

struct  CLoggingServiceProvider
 
struct  ExplorerInstance
 

Enumerations

enum  WaitType {
  Wait_None , Wait_Infinite , Wait_OpenWindows , Wait_Input ,
  Wait_ExplorerInstance
}
 

Functions

static void PrintHelp (PCWSTR ExtraLine=NULL)
 
static LONG StrToNum (PCWSTR in)
 
static int ErrMsg (int Error)
 
template<class T >
static bool CLSIDPrefix (T &String, CLSID &Clsid)
 
static IServiceProviderGetLoggingServiceProvider ()
 
static HRESULT GetUIObjectOfAbsolute (LPCITEMIDLIST pidl, REFIID riid, void **ppv)
 
static HRESULT CreateShellItemFromParse (PCWSTR Path, IShellItem **ppSI)
 
static void GetAssocClass (LPCWSTR Path, LPCITEMIDLIST pidl, HKEY &hKey)
 
static void DumpBytes (const void *Data, SIZE_T cb)
 
static HRESULT GetCommandString (IContextMenu &CM, UINT Id, UINT Type, LPWSTR buf, UINT cchMax)
 
static void DumpMenu (HMENU hMenu, UINT IdOffset, IContextMenu *pCM, BOOL FakeInit, UINT Indent)
 
static int SHGFI (PCWSTR Path)
 
static HRESULT AssocQ (int argc, WCHAR **argv)
 
HRESULT CreateIDataObject (CComHeapPtr< ITEMIDLIST > &pidl, CComPtr< IDataObject > &dataObject, PCWSTR FileName)
 
HRESULT LoadAndInitialize (REFIID riid, LPVOID *ppv)
 
BOOL CALLBACK EnumWindowsProc (HWND hwnd, LPARAM lParam)
 
void WaitWindows ()
 
static void Wait ()
 
static BOOL CALLBACK cb_AddPage (HPROPSHEETPAGE page, LPARAM lParam)
 
static bool isCmdWithArg (int argc, WCHAR **argv, int &n, PCWSTR check, PCWSTR &arg)
 
static bool isCmd (int argc, WCHAR **argv, int n, PCWSTR check)
 
int wmain (int argc, WCHAR **argv)
 

Variables

CLSID g_CLSID = { 0 }
 
CStringW g_DLL
 
CStringW g_ShellExtInit
 
bool g_bIShellPropSheetExt = false
 
CStringA g_ContextMenu
 
WaitType g_Wait = Wait_ExplorerInstance
 
CSimpleArray< HWNDg_Windows
 
HWND g_ConsoleWindow
 
ExplorerInstance g_EI
 
CSimpleArray< HPROPSHEETPAGEg_Pages
 

Enumeration Type Documentation

◆ WaitType

Enumerator
Wait_None 
Wait_Infinite 
Wait_OpenWindows 
Wait_Input 
Wait_ExplorerInstance 

Definition at line 417 of file shlextdbg.cpp.

418{
419 Wait_None,
424};
@ Wait_OpenWindows
Definition: shlextdbg.cpp:421
@ Wait_Input
Definition: shlextdbg.cpp:422
@ Wait_Infinite
Definition: shlextdbg.cpp:420
@ Wait_ExplorerInstance
Definition: shlextdbg.cpp:423
@ Wait_None
Definition: shlextdbg.cpp:419

Function Documentation

◆ AssocQ()

static HRESULT AssocQ ( int  argc,
WCHAR **  argv 
)
static

Definition at line 313 of file shlextdbg.cpp.

314{
315 UINT qtype = StrToNum(argv[2]);
316 ASSOCF iflags = StrToNum(argv[3]);
317 ASSOCF qflags = StrToNum(argv[4]);
318 PCWSTR extra = (argc > 6 && *argv[6]) ? argv[6] : NULL;
319 WCHAR buf[MAX_PATH * 2];
320 DWORD maxSize = (argc > 7 && *argv[7]) ? StrToNum(argv[7]) : sizeof(buf);
321
322 HRESULT hr;
324 PWSTR path = argv[0];
325 if (*path)
326 {
327 CLSID clsid, *pclsid = NULL;
328 if (CLSIDPrefix(path, clsid))
329 pclsid = &clsid;
332 {
333 hr = si->BindToHandler(NULL, pclsid ? *pclsid : BHID_AssociationArray, IID_PPV_ARG(IQueryAssociations, &qa));
334 if (FAILED(hr) && !pclsid)
335 hr = si->BindToHandler(NULL, BHID_SFUIObject, IID_PPV_ARG(IQueryAssociations, &qa));
336 }
337 }
338 else
339 {
340 hr = AssocCreate(CLSID_QueryAssociations, IID_PPV_ARG(IQueryAssociations, &qa));
341 }
342 if (FAILED(hr))
343 return ErrMsg(hr);
344 hr = qa->Init(iflags, argv[5], NULL, NULL);
345 if (FAILED(hr))
346 return ErrMsg(hr);
347
348 DWORD size = maxSize;
349 if (!_wcsicmp(argv[1], L"string"))
350 {
351 if (!_wcsicmp(argv[2], L"COMMAND"))
352 qtype = ASSOCSTR_COMMAND;
353 if (!_wcsicmp(argv[2], L"EXECUTABLE"))
354 qtype = ASSOCSTR_EXECUTABLE;
355 if (!_wcsicmp(argv[2], L"FRIENDLYDOCNAME") || !_wcsicmp(argv[2], L"FriendlyTypeName"))
357 if (!_wcsicmp(argv[2], L"DEFAULTICON"))
358 qtype = ASSOCSTR_DEFAULTICON;
359
360 buf[0] = UNICODE_NULL;
361 size /= sizeof(buf[0]); // Convert to number of characters
362 hr = qa->GetString(qflags, (ASSOCSTR)qtype, extra, buf, &size);
363 size *= sizeof(buf[0]); // Convert back to bytes
364 if (SUCCEEDED(hr) ||
366 {
367 wprintf(L"0x%.8X: %s\n", hr, buf);
368 }
369 else
370 {
371 wprintf(size != maxSize ? L"%u " : L"", size);
372 ErrMsg(hr);
373 }
374 }
375 else if (!_wcsicmp(argv[1], L"data"))
376 {
377 if (!_wcsicmp(argv[2], L"EDITFLAGS"))
378 qtype = ASSOCDATA_EDITFLAGS;
379 if (!_wcsicmp(argv[2], L"VALUE"))
380 qtype = ASSOCDATA_VALUE;
381
382 hr = qa->GetData(qflags, (ASSOCDATA)qtype, extra, buf, &size);
383 if (SUCCEEDED(hr))
384 {
385 wprintf(L"0x%.8X: %u byte(s) ", hr, size);
386 DumpBytes(buf, min(size, maxSize));
387 }
388 else
389 {
390 wprintf(size != maxSize ? L"%u " : L"", size);
391 ErrMsg(hr);
392 }
393 }
394 else if (!_wcsicmp(argv[1], L"key"))
395 {
396 HKEY hKey = NULL;
397 hr = qa->GetKey(qflags, (ASSOCKEY)qtype, extra, &hKey);
398 if (SUCCEEDED(hr))
399 {
400 wprintf(L"0x%.8X: hKey %p\n", hr, hKey);
401 RegQueryValueExW(hKey, L"shlextdbg", 0, NULL, NULL, NULL); // Filter by this in Process Monitor
403 }
404 else
405 {
406 ErrMsg(hr);
407 }
408 }
409 else
410 {
411 PrintHelp(L"Unknown query");
413 }
414 return hr;
415}
static int argc
Definition: ServiceArgs.c:12
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define NULL
Definition: types.h:112
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define MAX_PATH
Definition: compat.h:34
HRESULT WINAPI AssocCreate(CLSID clsid, REFIID refiid, void **lpInterface)
Definition: assoc.c:99
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
@ extra
Definition: id3.c:95
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
void PrintHelp()
Definition: appwiz.c:21
#define min(a, b)
Definition: monoChain.cc:55
#define argv
Definition: mplay32.c:18
const CLSID * clsid
Definition: msctf.cpp:51
unsigned int UINT
Definition: ndis.h:50
#define UNICODE_NULL
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
static bool CLSIDPrefix(T &String, CLSID &Clsid)
Definition: shlextdbg.cpp:89
static LONG StrToNum(PCWSTR in)
Definition: shlextdbg.cpp:64
static void DumpBytes(const void *Data, SIZE_T cb)
Definition: shlextdbg.cpp:198
static HRESULT CreateShellItemFromParse(PCWSTR Path, IShellItem **ppSI)
Definition: shlextdbg.cpp:146
static int ErrMsg(int Error)
Definition: shlextdbg.cpp:71
HRESULT hr
Definition: shlfolder.c:183
ASSOCDATA
Definition: shlwapi.h:641
@ ASSOCDATA_EDITFLAGS
Definition: shlwapi.h:646
@ ASSOCDATA_VALUE
Definition: shlwapi.h:647
ASSOCSTR
Definition: shlwapi.h:611
@ ASSOCSTR_COMMAND
Definition: shlwapi.h:612
@ ASSOCSTR_FRIENDLYDOCNAME
Definition: shlwapi.h:614
@ ASSOCSTR_EXECUTABLE
Definition: shlwapi.h:613
@ ASSOCSTR_DEFAULTICON
Definition: shlwapi.h:626
ASSOCKEY
Definition: shlwapi.h:632
DWORD ASSOCF
Definition: shlwapi.h:608
uint16_t * PWSTR
Definition: typedefs.h:56
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define wprintf(...)
Definition: whoami.c:18
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:211
#define IID_PPV_ARG(Itype, ppType)
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by wmain().

◆ cb_AddPage()

static BOOL CALLBACK cb_AddPage ( HPROPSHEETPAGE  page,
LPARAM  lParam 
)
static

Definition at line 631 of file shlextdbg.cpp.

632{
633 g_Pages.Add(page);
634 if (lParam != (LPARAM)&g_Pages)
635 {
636 wprintf(L"Propsheet failed to pass lParam, got: 0x%Ix\n", lParam);
637 }
638 return TRUE;
639}
LPARAM lParam
Definition: combotst.c:139
#define TRUE
Definition: types.h:120
CSimpleArray< HPROPSHEETPAGE > g_Pages
Definition: shlextdbg.cpp:630
Definition: module.h:576
LONG_PTR LPARAM
Definition: windef.h:208

Referenced by wmain().

◆ CLSIDPrefix()

template<class T >
static bool CLSIDPrefix ( T String,
CLSID Clsid 
)
static

Definition at line 89 of file shlextdbg.cpp.

90{
91 WCHAR buf[38 + 1];
92 if (String[0] == '{')
93 {
95 if (SUCCEEDED(CLSIDFromString(buf, &Clsid)))
96 {
97 String = String + 38;
98 return true;
99 }
100 }
101 return false;
102}
#define lstrcpynW
Definition: compat.h:738
HRESULT WINAPI CLSIDFromString(LPCOLESTR idstr, LPCLSID id)
Definition: compobj.c:2338
#define _countof(array)
Definition: sndvol32.h:70
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433

Referenced by AssocQ(), and wmain().

◆ CreateIDataObject()

HRESULT CreateIDataObject ( CComHeapPtr< ITEMIDLIST > &  pidl,
CComPtr< IDataObject > &  dataObject,
PCWSTR  FileName 
)

Definition at line 433 of file shlextdbg.cpp.

434{
436 if (!SUCCEEDED(hr))
437 {
438 wprintf(L"Failed to create pidl from '%s': 0x%x\n", FileName, hr);
439 return hr;
440 }
441
442 CComPtr<IShellFolder> shellFolder;
443 PCUITEMID_CHILD childs;
444 hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &shellFolder), &childs);
445 if (!SUCCEEDED(hr))
446 {
447 wprintf(L"Failed to bind to parent: 0x%x\n", hr);
448 return hr;
449 }
450 hr = shellFolder->GetUIObjectOf(NULL, 1, &childs, IID_IDataObject, NULL, (PVOID*)&dataObject);
451 if (!SUCCEEDED(hr))
452 {
453 wprintf(L"Failed to query IDataObject: 0x%x\n", hr);
454 }
455 return hr;
456}
const GUID IID_IDataObject
HRESULT WINAPI SHParseDisplayName(LPCWSTR pszName, IBindCtx *pbc, LPITEMIDLIST *ppidl, SFGAOF sfgaoIn, SFGAOF *psfgaoOut)
Definition: pidl.c:1542
HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
Definition: pidl.c:1498
const ITEMID_CHILD UNALIGNED * PCUITEMID_CHILD
Definition: shtypes.idl:70

Referenced by LoadAndInitialize().

◆ CreateShellItemFromParse()

static HRESULT CreateShellItemFromParse ( PCWSTR  Path,
IShellItem **  ppSI 
)
static

Definition at line 146 of file shlextdbg.cpp.

147{
148 PIDLIST_ABSOLUTE pidl = NULL;
149 HRESULT hr = SHParseDisplayName(Path, NULL, &pidl, 0, NULL);
150 if (SUCCEEDED(hr))
151 {
152 hr = SHCreateShellItem(NULL, NULL, pidl, ppSI);
153 SHFree(pidl);
154 }
155 return hr;
156}
EXTERN_C HRESULT WINAPI SHCreateShellItem(PCIDLIST_ABSOLUTE pidlParent, IShellFolder *psfParent, PCUITEMID_CHILD pidl, IShellItem **ppsi)
Definition: CShellItem.cpp:264
PRTL_UNICODE_STRING_BUFFER Path
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:370

Referenced by AssocQ(), and wmain().

◆ DumpBytes()

static void DumpBytes ( const void Data,
SIZE_T  cb 
)
static

Definition at line 198 of file shlextdbg.cpp.

199{
200 for (SIZE_T i = 0; i < cb; ++i)
201 {
202 wprintf(L"%s%.2X", i ? L" " : L"", ((LPCBYTE)Data)[i]);
203 }
204 wprintf(L"\n");
205}
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
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33
ULONG_PTR SIZE_T
Definition: typedefs.h:80
const BYTE * LPCBYTE
Definition: winscard.h:34

Referenced by AssocQ().

◆ DumpMenu()

static void DumpMenu ( HMENU  hMenu,
UINT  IdOffset,
IContextMenu pCM,
BOOL  FakeInit,
UINT  Indent 
)
static

Definition at line 226 of file shlextdbg.cpp.

227{
228 bool recurse = Indent != UINT(-1);
230 MENUITEMINFOW mii;
231 mii.cbSize = FIELD_OFFSET(MENUITEMINFOW, hbmpItem);
232
233 for (UINT i = 0, defid = GetMenuDefaultItem(hMenu, FALSE, 0); ; ++i)
234 {
235 mii.fMask = MIIM_STRING;
236 mii.dwTypeData = buf;
237 mii.cch = _countof(buf);
238 *buf = UNICODE_NULL;
239 if (!GetMenuItemInfo(hMenu, i, TRUE, &mii))
240 lstrcpynW(buf, L"?", _countof(buf)); // Tolerate string failure
242 mii.hSubMenu = NULL;
243 mii.dwTypeData = NULL;
244 mii.cch = 0;
245 if (!GetMenuItemInfo(hMenu, i, TRUE, &mii))
246 break;
247
248 BOOL sep = mii.fType & MFT_SEPARATOR;
249 wprintf(L"%-4d", (sep || mii.wID == UINT(-1)) ? mii.wID : (mii.wID - IdOffset));
250 for (UINT j = 0; j < Indent && recurse; ++j)
251 wprintf(L" ");
252 wprintf(L"%s%s", mii.hSubMenu ? L">" : L"|", sep ? L"----------" : buf);
253 if (!sep && pCM && SUCCEEDED(GetCommandString(*pCM, mii.wID - IdOffset,
254 GCS_VERB, buf, _countof(buf))))
255 {
256 wprintf(L" [%s]", buf);
257 }
258 wprintf(L"%s\n", (defid == mii.wID && defid != UINT(-1)) ? L" (Default)" : L"");
259 if (mii.hSubMenu && recurse)
260 {
261 if (FakeInit)
263 DumpMenu(mii.hSubMenu, IdOffset, pCM, FakeInit, Indent + 1);
264 }
265 }
266}
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
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 GLint GLint j
Definition: glfuncs.h:250
#define LOWORD(l)
Definition: pedump.c:82
HRESULT WINAPI SHForwardContextMenuMsg(IUnknown *pUnk, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult, BOOL useIContextMenu2)
Definition: rosordinal.c:11
static HRESULT GetCommandString(IContextMenu &CM, UINT Id, UINT Type, LPWSTR buf, UINT cchMax)
Definition: shlextdbg.cpp:207
static void DumpMenu(HMENU hMenu, UINT IdOffset, IContextMenu *pCM, BOOL FakeInit, UINT Indent)
Definition: shlextdbg.cpp:226
LPWSTR dwTypeData
Definition: winuser.h:3371
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
UINT_PTR WPARAM
Definition: windef.h:207
UINT WINAPI GetMenuDefaultItem(_In_ HMENU hMenu, _In_ UINT fByPos, _In_ UINT gmdiFlags)
#define MIIM_STRING
Definition: winuser.h:738
#define MIIM_ID
Definition: winuser.h:733
#define MIIM_FTYPE
Definition: winuser.h:740
#define MFT_SEPARATOR
Definition: winuser.h:755
#define MIIM_SUBMENU
Definition: winuser.h:734
#define WM_INITMENUPOPUP
Definition: winuser.h:1774
#define GetMenuItemInfo
Definition: winuser.h:5899

Referenced by DumpMenu(), and wmain().

◆ EnumWindowsProc()

BOOL CALLBACK EnumWindowsProc ( HWND  hwnd,
LPARAM  lParam 
)

Definition at line 532 of file shlextdbg.cpp.

533{
534 if (hwnd != g_ConsoleWindow)
535 {
536 DWORD pid = 0;
538 if (pid == GetCurrentProcessId())
539 {
540 g_Windows.Add(hwnd);
541 }
542 }
543 return TRUE;
544}
CSimpleArray< HWND > g_Windows
Definition: shlextdbg.cpp:530
HWND g_ConsoleWindow
Definition: shlextdbg.cpp:531
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1158
DWORD WINAPI GetWindowThreadProcessId(HWND hWnd, PDWORD lpdwProcessId)
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
_In_ ULONG_PTR _In_ ULONG _Out_ ULONG_PTR * pid
Definition: winddi.h:3837

Referenced by WaitWindows().

◆ ErrMsg()

static int ErrMsg ( int  Error)
static

Definition at line 71 of file shlextdbg.cpp.

72{
73 WCHAR buf[400];
74 for (UINT e = Error, cch; ;)
75 {
76 lstrcpynW(buf, L"?", _countof(buf));
78 while (cch && buf[cch - 1] <= ' ')
79 buf[--cch] = UNICODE_NULL; // Remove trailing newlines
80 if (cch || HIWORD(e) != HIWORD(HRESULT_FROM_WIN32(1)))
81 break;
82 e = HRESULT_CODE(e); // "WIN32_FROM_HRESULT"
83 }
84 wprintf(Error < 0 ? L"Error 0x%.8X %s\n" : L"Error %d %s\n", Error, buf);
85 return Error;
86}
BOOL Error
Definition: chkdsk.c:66
#define e
Definition: ke_i.h:82
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:202
#define HIWORD(l)
Definition: typedefs.h:247
#define FormatMessage
Definition: winbase.h:3836
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:453
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:456
#define HRESULT_CODE(hr)
Definition: winerror.h:189

Referenced by AssocQ(), SHGFI(), and wmain().

◆ GetAssocClass()

static void GetAssocClass ( LPCWSTR  Path,
LPCITEMIDLIST  pidl,
HKEY hKey 
)
static

Definition at line 158 of file shlextdbg.cpp.

159{
160 hKey = NULL;
161 IQueryAssociations* pQA;
162 if (SUCCEEDED(GetUIObjectOfAbsolute(pidl, IID_PPV_ARG(IQueryAssociations, &pQA))))
163 {
164 pQA->GetKey(0, ASSOCKEY_CLASS, NULL, &hKey); // Not implemented in ROS
165 pQA->Release();
166 }
167 if (!hKey)
168 {
169 DWORD cb;
173 info.dwAttributes = 0;
175 if (info.dwAttributes & SFGAO_FOLDER)
176 {
177 ext = const_cast<LPWSTR>(L"Directory");
178 }
179 else if (info.dwAttributes & SFGAO_BROWSABLE)
180 {
181 ext = const_cast<LPWSTR>(L"Folder"); // Best guess
182 }
183 else
184 {
185 cb = sizeof(buf);
187 {
189 }
190 }
191 if (!hKey)
192 {
194 }
195 }
196}
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
static const WCHAR *const ext[]
Definition: module.c:53
LPWSTR WINAPI PathFindExtensionW(const WCHAR *path)
Definition: path.c:1274
DWORD WINAPI SHGetValueW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue, LPDWORD pwType, LPVOID pvData, LPDWORD pcbData)
Definition: reg.c:1236
#define KEY_READ
Definition: nt_native.h:1023
DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path, DWORD dwFileAttributes, SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags)
Definition: shell32_main.c:430
#define SHGFI_ATTRIBUTES
Definition: shellapi.h:168
#define SHGFI_PIDL
Definition: shellapi.h:180
static HRESULT GetUIObjectOfAbsolute(LPCITEMIDLIST pidl, REFIID riid, void **ppv)
Definition: shlextdbg.cpp:136
@ ASSOCKEY_CLASS
Definition: shlwapi.h:635
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by LoadAndInitialize().

◆ GetCommandString()

static HRESULT GetCommandString ( IContextMenu CM,
UINT  Id,
UINT  Type,
LPWSTR  buf,
UINT  cchMax 
)
static

Definition at line 207 of file shlextdbg.cpp.

208{
209 if (cchMax < 1) return E_INVALIDARG;
210 *buf = UNICODE_NULL;
211
212 // First try to retrieve the UNICODE string directly
213 HRESULT hr = CM.GetCommandString(Id, Type | GCS_UNICODE, 0, (char*)buf, cchMax);
214 if (FAILED(hr))
215 {
216 // It failed, try to retrieve an ANSI string instead then convert it to UNICODE
217 STRRET sr;
218 sr.uType = STRRET_CSTR;
219 hr = CM.GetCommandString(Id, Type & ~GCS_UNICODE, 0, sr.cStr, _countof(sr.cStr));
220 if (SUCCEEDED(hr))
221 hr = StrRetToBufW(&sr, NULL, buf, cchMax);
222 }
223 return hr;
224}
DWORD Id
UINT cchMax
Type
Definition: Type.h:7
#define E_INVALIDARG
Definition: ddrawi.h:101
HRESULT WINAPI StrRetToBufW(LPSTRRET src, const ITEMIDLIST *pidl, LPWSTR dest, UINT len)
Definition: string.c:1530
HRESULT GetCommandString([in] UINT_PTR idCmd, [in] UINT uType, [out] UINT *pwReserved, [out, size_is(cchMax)] LPSTR pszName, [in] UINT cchMax)
@ STRRET_CSTR
Definition: shtypes.idl:87
char cStr[MAX_PATH]
Definition: shtypes.idl:98
UINT uType
Definition: shtypes.idl:93

Referenced by DumpMenu().

◆ GetLoggingServiceProvider()

static IServiceProvider * GetLoggingServiceProvider ( )
static

Definition at line 130 of file shlextdbg.cpp.

131{
132 static CLoggingServiceProvider g_SP;
133 return &g_SP;
134}

Referenced by wmain().

◆ GetUIObjectOfAbsolute()

static HRESULT GetUIObjectOfAbsolute ( LPCITEMIDLIST  pidl,
REFIID  riid,
void **  ppv 
)
static

Definition at line 136 of file shlextdbg.cpp.

137{
138 CComPtr<IShellFolder> shellFolder;
140 HRESULT hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &shellFolder), &child);
141 if (SUCCEEDED(hr))
142 hr = shellFolder->GetUIObjectOf(NULL, 1, &child, riid, NULL, ppv);
143 return hr;
144}
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
static HWND child
Definition: cursoricon.c:298

Referenced by GetAssocClass().

◆ isCmd()

static bool isCmd ( int  argc,
WCHAR **  argv,
int  n,
PCWSTR  check 
)
static

Definition at line 665 of file shlextdbg.cpp.

666{
667 return !_wcsicmp(argv[n] + 1, check);
668}
#define check(expected, result)
Definition: dplayx.c:32
GLdouble n
Definition: glext.h:7729

Referenced by wmain().

◆ isCmdWithArg()

static bool isCmdWithArg ( int  argc,
WCHAR **  argv,
int n,
PCWSTR  check,
PCWSTR arg 
)
static

Definition at line 641 of file shlextdbg.cpp.

642{
643 arg = NULL;
644 size_t len = wcslen(check);
645 if (!_wcsnicmp(argv[n] + 1, check, len))
646 {
647 PCWSTR cmd = argv[n] + len + 1;
648 if (*cmd == ':' || *cmd == '=')
649 {
650 arg = cmd + 1;
651 return true;
652 }
653 if (n + 1 < argc)
654 {
655 arg = argv[n+1];
656 n++;
657 return true;
658 }
659 wprintf(L"Command %s has no required argument!\n", check);
660 return false;
661 }
662 return false;
663}
GLenum GLsizei len
Definition: glext.h:6722
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
Definition: ftp_var.h:139

Referenced by wmain().

◆ LoadAndInitialize()

HRESULT LoadAndInitialize ( REFIID  riid,
LPVOID ppv 
)

Definition at line 458 of file shlextdbg.cpp.

459{
460 CComPtr<IShellExtInit> spShellExtInit;
461 HRESULT hr;
462 if (g_DLL.IsEmpty())
463 {
464 hr = CoCreateInstance(g_CLSID, NULL, CLSCTX_ALL, IID_PPV_ARG(IShellExtInit, &spShellExtInit));
465 if (!SUCCEEDED(hr))
466 {
467 WCHAR Buffer[100];
469 wprintf(L"Failed to Create %s:IShellExtInit: 0x%x\n", Buffer, hr);
470 return hr;
471 }
472 }
473 else
474 {
475 typedef HRESULT (STDAPICALLTYPE *tDllGetClassObject)(REFCLSID rclsid, REFIID riid, LPVOID *ppv);
477 if (!mod)
478 {
479 wprintf(L"Failed to Load %s:(0x%x)\n", g_DLL.GetString(), GetLastError());
480 return E_FAIL;
481 }
482 tDllGetClassObject DllGet = (tDllGetClassObject)GetProcAddress(mod, "DllGetClassObject");
483 if (!DllGet)
484 {
485 wprintf(L"%s does not export DllGetClassObject\n", g_DLL.GetString());
486 return E_FAIL;
487 }
488 CComPtr<IClassFactory> spClassFactory;
489 hr = DllGet(g_CLSID, IID_PPV_ARG(IClassFactory, &spClassFactory));
490 if (!SUCCEEDED(hr))
491 {
492 wprintf(L"Failed to create IClassFactory: 0x%x\n", hr);
493 return hr;
494 }
495 hr = spClassFactory->CreateInstance(NULL, IID_PPV_ARG(IShellExtInit, &spShellExtInit));
496 if (!SUCCEEDED(hr))
497 {
498 wprintf(L"Failed to Request IShellExtInit from IClassFactory: 0x%x\n", hr);
499 return hr;
500 }
501 }
502
503 CComPtr<IDataObject> spDataObject;
505 hr = CreateIDataObject(pidl, spDataObject, g_ShellExtInit.GetString());
506 if (!SUCCEEDED(hr))
507 return hr;
508
509 HKEY hKey = NULL;
511 hr = spShellExtInit->Initialize(pidl, spDataObject, hKey);
512 if (hKey)
514 if (!SUCCEEDED(hr))
515 {
516 wprintf(L"IShellExtInit->Initialize failed: 0x%x\n", hr);
517 return hr;
518 }
519 hr = spShellExtInit->QueryInterface(riid, ppv);
520 if (!SUCCEEDED(hr))
521 {
522 WCHAR Buffer[100];
524 wprintf(L"Failed to query %s from IShellExtInit: 0x%x\n", Buffer, hr);
525 }
526 return hr;
527}
std::map< E_MODULE, HMODULE > mod
Definition: LocaleTests.cpp:66
bool IsEmpty() const noexcept
Definition: atlsimpstr.h:394
PXSTR GetString() noexcept
Definition: atlsimpstr.h:367
Definition: bufpool.h:45
#define E_FAIL
Definition: ddrawi.h:102
#define GetProcAddress(x, y)
Definition: compat.h:753
#define LoadLibraryW(x)
Definition: compat.h:747
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
INT WINAPI StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
Definition: compobj.c:2434
#define STDAPICALLTYPE
Definition: guid.c:3
#define REFIID
Definition: guiddef.h:118
#define REFCLSID
Definition: guiddef.h:117
CLSID g_CLSID
Definition: shlextdbg.cpp:426
static void GetAssocClass(LPCWSTR Path, LPCITEMIDLIST pidl, HKEY &hKey)
Definition: shlextdbg.cpp:158
CStringW g_ShellExtInit
Definition: shlextdbg.cpp:428
HRESULT CreateIDataObject(CComHeapPtr< ITEMIDLIST > &pidl, CComPtr< IDataObject > &dataObject, PCWSTR FileName)
Definition: shlextdbg.cpp:433
CStringW g_DLL
Definition: shlextdbg.cpp:427
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by wmain().

◆ PrintHelp()

static void PrintHelp ( PCWSTR  ExtraLine = NULL)
static

Definition at line 19 of file shlextdbg.cpp.

20{
21 if (ExtraLine)
22 wprintf(L"%s\n\n", ExtraLine);
23
24 wprintf(L"shlextdbg /clsid={clsid} [/dll=dllname] /IShellExtInit=filename |shlextype| |waitoptions|\n");
25 wprintf(L" {clsid}: The CLSID or ProgID of the object to create\n");
26 wprintf(L" dll: Optional dllname to create the object from, instead of CoCreateInstance\n");
27 wprintf(L" filename: The filename to pass to IShellExtInit->Initialze\n");
28 wprintf(L" shlextype: The type of shell extention to run:\n");
29 wprintf(L" /IShellPropSheetExt to create a property sheet\n");
30 wprintf(L" /IContextMenu=verb to activate the specified verb\n");
31 wprintf(L" waitoptions: Specify how to wait:\n");
32 wprintf(L" /explorerinstance: Wait for SHGetInstanceExplorer (Default)\n");
33 wprintf(L" /infinite: Keep on waiting infinitely\n");
34 wprintf(L" /openwindows: Wait for all windows from the current application to close\n");
35 wprintf(L" /input: Wait for input\n");
36 wprintf(L" /nowait\n");
37 wprintf(L"\n");
38 wprintf(L"shlextdbg /shgfi=path\n");
39 wprintf(L" Call SHGetFileInfo. Prefix path with $ to parse as a pidl.\n");
40 wprintf(L"\n");
41 wprintf(L"shlextdbg /assocq <[{bhid}]path> <string|data|key> <type> <initflags> <queryflags> <initstring> [extra] [maxsize]\n");
42 wprintf(L" Uses the default implementation from AssocCreate if path is empty.\n");
43 wprintf(L"\n");
44 wprintf(L"shlextdbg /shellexec=path [/see] [verb] [class]\n");
45 wprintf(L"\n");
46 wprintf(L"shlextdbg /dumpmenu=[{clsid}]path [/cmf]\n");
47}

◆ SHGFI()

static int SHGFI ( PCWSTR  Path)
static

Definition at line 268 of file shlextdbg.cpp.

269{
270 PIDLIST_ABSOLUTE pidl = NULL;
271 UINT flags = 0, ret = 0;
272
273 if (*Path == L'$')
274 {
275 HRESULT hr = SHParseDisplayName(++Path, NULL, &pidl, 0, NULL);
276 if (FAILED(hr))
277 return ErrMsg(hr);
278 flags |= SHGFI_PIDL;
279 Path = (LPCWSTR)pidl;
280 }
282 {
284 }
286 if (!SHGetFileInfoW(Path, 0, &info, sizeof(info), flags |
288 {
289 info.szDisplayName[0] = info.szTypeName[0] = UNICODE_NULL;
290 info.dwAttributes = 0;
292 }
293 wprintf(L"Display: %s\n", info.szDisplayName);
294 wprintf(L"Attributes: 0x%x\n", info.dwAttributes);
295 wprintf(L"Type: %s\n", info.szTypeName);
296
297 if (!SHGetFileInfoW(Path, 0, &info, sizeof(info), flags | SHGFI_ICONLOCATION))
298 {
299 info.szDisplayName[0] = UNICODE_NULL;
300 info.iIcon = -1;
301 }
302 wprintf(L"Icon: %s,%d\n", info.szDisplayName, info.iIcon);
303
304 if (!SHGetFileInfoW(Path, 0, &info, sizeof(info), flags | SHGFI_SYSICONINDEX))
305 {
306 info.iIcon = -1;
307 }
308 wprintf(L"Index: %d\n", info.iIcon);
309 SHFree(pidl);
310 return ret;
311}
return ret
Definition: mutex.c:146
GLbitfield flags
Definition: glext.h:7161
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define SHGFI_SYSICONINDEX
Definition: shellapi.h:171
#define SHGFI_ICONLOCATION
Definition: shellapi.h:169
#define SHGFI_DISPLAYNAME
Definition: shellapi.h:166
#define SHGFI_TYPENAME
Definition: shellapi.h:167
#define SHGFI_USEFILEATTRIBUTES
Definition: shellapi.h:181
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define GetFileAttributes
Definition: winbase.h:3856
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by wmain().

◆ StrToNum()

static LONG StrToNum ( PCWSTR  in)
static

Definition at line 64 of file shlextdbg.cpp.

65{
66 PWCHAR end;
67 LONG v = wcstol(in, &end, 0);
68 return (end > in) ? v : 0;
69}
const GLdouble * v
Definition: gl.h:2040
GLuint GLuint end
Definition: gl.h:1545
GLuint in
Definition: glext.h:9616
long LONG
Definition: pedump.c:60
_Check_return_ long __cdecl wcstol(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
uint16_t * PWCHAR
Definition: typedefs.h:56

Referenced by AssocQ().

◆ Wait()

static void Wait ( )
static

Definition at line 604 of file shlextdbg.cpp.

605{
606 LPCWSTR nag = L"(Please use SHGetInstanceExplorer in your code instead)";
607 switch (g_Wait)
608 {
609 case Wait_None:
610 break;
611 case Wait_Infinite:
612 _putws(nag);
613 while (true)
614 Sleep(1000);
615 break;
616 case Wait_OpenWindows:
617 _putws(nag);
618 WaitWindows();
619 break;
620 case Wait_Input:
621 wprintf(L"Press any key to continue... %s\n", nag);
622 _getch();
623 break;
625 g_EI.Wait();
626 break;
627 }
628}
_Check_return_opt_ _CRTIMP int __cdecl _putws(_In_z_ const wchar_t *_Str)
int _getch()
Definition: getch.c:16
WaitType g_Wait
Definition: shlextdbg.cpp:431
ExplorerInstance g_EI
void WaitWindows()
Definition: shlextdbg.cpp:546
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790

Referenced by wmain().

◆ WaitWindows()

void WaitWindows ( )

Definition at line 546 of file shlextdbg.cpp.

547{
548 /* Give the windows some time to spawn */
549 Sleep(2000);
551 while (true)
552 {
553 g_Windows.RemoveAll();
555 if (g_Windows.GetSize() == 0)
556 break;
557 Sleep(500);
558 }
559 wprintf(L"All windows closed (ignoring console window)\n");
560}
HWND WINAPI GetConsoleWindow(void)
Definition: console.c:1102
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
Definition: shlextdbg.cpp:532
BOOL WINAPI EnumWindows(_In_ WNDENUMPROC lpEnumFunc, _In_ LPARAM lParam)

Referenced by Wait().

◆ wmain()

int wmain ( int  argc,
WCHAR **  argv 
)

Definition at line 671 of file shlextdbg.cpp.

672{
676 SHSetInstanceExplorer(static_cast<IUnknown*>(&g_EI));
677
678 bool failArgs = false;
679 for (int n = 1; n < argc; ++n)
680 {
681 WCHAR* cmd = argv[n];
682 if (cmd[0] == '-' || cmd[0] == '/')
683 {
684 PCWSTR arg;
685 if (isCmdWithArg(argc, argv, n, L"shgfi", arg))
686 {
687 failArgs = true;
688 if (*arg)
689 return SHGFI(arg);
690 }
691 else if (isCmd(argc, argv, n, L"assocq"))
692 {
693 failArgs = true;
694 if (argc - (n + 1) >= 6 && argc - (n + 1) <= 8)
695 return AssocQ(argc - (n + 1), &argv[(n + 1)]);
696 }
697 else if (isCmdWithArg(argc, argv, n, L"shellexec", arg))
698 {
699 PIDLIST_ABSOLUTE pidl = NULL;
700 HRESULT hr = SHParseDisplayName(arg, NULL, &pidl, 0, NULL);
701 if (FAILED(hr))
702 return ErrMsg(hr);
703 SHELLEXECUTEINFOW sei = { sizeof(sei), SEE_MASK_IDLIST | SEE_MASK_UNICODE };
704 sei.lpIDList = pidl;
705 sei.nShow = SW_SHOW;
706 while (++n < argc)
707 {
708 if (argv[n][0] != '-' && argv[n][0] != '/')
709 break;
710 else if (isCmd(argc, argv, n, L"MIN"))
712 else if (isCmd(argc, argv, n, L"MAX"))
714 else if (isCmd(argc, argv, n, L"INVOKE"))
716 else if (isCmd(argc, argv, n, L"NOUI"))
718 else if (isCmd(argc, argv, n, L"ASYNCOK"))
719 sei.fMask |= SEE_MASK_ASYNCOK ;
720 else if (isCmd(argc, argv, n, L"NOASYNC"))
721 sei.fMask |= SEE_MASK_NOASYNC;
722 else if (isCmd(argc, argv, n, L"NOCONSOLE"))
724 else if (isCmd(argc, argv, n, L"1000"))
725 sei.fMask |= 0x00001000; // Unknown flag
726 else if (isCmd(argc, argv, n, L"NOHOOKS"))
727 sei.fMask |= 0x00002000;
728 else if (isCmd(argc, argv, n, L"SITE"))
729 {
730 sei.fMask |= 0x08000000; // SEE_MASK_FLAG_HINST_IS_SITE
732 }
733 else if (isCmd(argc, argv, n, L"FILL"))
734 {
735 sei.hInstApp = (HINSTANCE)UlongToHandle(0xCAFE);
736 sei.hProcess = UlongToHandle(0xDEADF00D);
737 }
738 else
739 wprintf(L"WARN: Ignoring switch %s\n", argv[n]);
740 }
741 if (n < argc && *argv[n++])
742 {
743 sei.lpVerb = argv[n - 1];
744 }
745 if (n < argc && *argv[n++])
746 {
747 sei.lpClass = argv[n - 1];
749 }
750 UINT succ = ShellExecuteExW(&sei), gle = GetLastError();
751 SHFree(pidl);
752 if (!succ)
753 return ErrMsg(gle);
754 Wait();
755 return 0;
756 }
757 else if (isCmdWithArg(argc, argv, n, L"dumpmenu", arg))
758 {
759 HRESULT hr;
761 if (CLSIDPrefix(arg, g_CLSID))
762 {
765 }
766 else
767 {
770 if (SUCCEEDED(hr))
771 hr = si->BindToHandler(NULL, BHID_SFUIObject, IID_PPV_ARG(IContextMenu, &cm));
772 }
773 if (SUCCEEDED(hr))
774 {
775 UINT first = 10, last = 9000;
776 UINT cmf = 0, nosub = 0, fakeinit = 0;
777 while (++n < argc)
778 {
779 if (argv[n][0] != '-' && argv[n][0] != '/')
780 break;
781 else if (isCmd(argc, argv, n, L"DEFAULTONLY"))
782 cmf |= CMF_DEFAULTONLY;
783 else if (isCmd(argc, argv, n, L"NODEFAULT"))
784 cmf |= CMF_NODEFAULT;
785 else if (isCmd(argc, argv, n, L"DONOTPICKDEFAULT"))
786 cmf |= CMF_DONOTPICKDEFAULT;
787 else if (isCmd(argc, argv, n, L"EXTENDED") || isCmd(argc, argv, n, L"EXTENDEDVERBS"))
788 cmf |= CMF_EXTENDEDVERBS;
789 else if (isCmd(argc, argv, n, L"SYNCCASCADEMENU"))
790 cmf |= CMF_SYNCCASCADEMENU;
791 else if (isCmd(argc, argv, n, L"EXPLORE"))
792 cmf |= CMF_EXPLORE;
793 else if (isCmd(argc, argv, n, L"VERBSONLY"))
794 cmf |= CMF_VERBSONLY;
795 else if (isCmd(argc, argv, n, L"NOVERBS"))
796 cmf |= CMF_NOVERBS;
797 else if (isCmd(argc, argv, n, L"DISABLEDVERBS"))
798 cmf |= CMF_DISABLEDVERBS;
799 else if (isCmd(argc, argv, n, L"OPTIMIZEFORINVOKE"))
800 cmf |= CMF_OPTIMIZEFORINVOKE;
801 else if (isCmd(argc, argv, n, L"CANRENAME"))
802 cmf |= CMF_CANRENAME;
803 else if (isCmd(argc, argv, n, L"NOSUBMENU"))
804 nosub++;
805 else if (isCmd(argc, argv, n, L"INITMENUPOPUP"))
806 fakeinit++; // Tickle async submenus
807 else
808 wprintf(L"WARN: Ignoring switch %s\n", argv[n]);
809 }
810 HMENU hMenu = CreatePopupMenu();
811 hr = cm->QueryContextMenu(hMenu, 0, first, last, cmf);
812 if (SUCCEEDED(hr))
813 {
814 DumpMenu(hMenu, first, cm, fakeinit, nosub ? -1 : 0);
815 }
816 DestroyMenu(hMenu);
817 }
818 if (FAILED(hr))
819 return ErrMsg(hr);
820 return 0;
821 }
822 else if (isCmdWithArg(argc, argv, n, L"clsid", arg))
823 {
825 if (!SUCCEEDED(hr))
826 {
827 wprintf(L"Failed to convert %s to CLSID\n", arg);
828 failArgs = true;
829 }
830 }
831 else if (isCmdWithArg(argc, argv, n, L"dll", arg))
832 {
833 g_DLL = arg;
834 }
835 else if (isCmdWithArg(argc, argv, n, L"IShellExtInit", arg))
836 {
838 }
839 else if (isCmd(argc, argv, n, L"IShellPropSheetExt"))
840 {
842 }
843 else if (isCmdWithArg(argc, argv, n, L"IContextMenu", arg))
844 {
846 }
847 else if (isCmd(argc, argv, n, L"infinite"))
848 {
850 }
851 else if (isCmd(argc, argv, n, L"openwindows"))
852 {
854 }
855 else if (isCmd(argc, argv, n, L"input"))
856 {
858 }
859 else if (isCmd(argc, argv, n, L"explorerinstance"))
860 {
862 }
863 else if (isCmd(argc, argv, n, L"nowait"))
864 {
866 }
867 else
868 {
869 wprintf(L"Unknown argument: %s\n", cmd);
870 failArgs = true;
871 }
872 }
873 }
874
875 if (failArgs)
876 {
878 return E_INVALIDARG;
879 }
880
881 CLSID EmptyCLSID = { 0 };
882 if (EmptyCLSID == g_CLSID)
883 {
884 PrintHelp(L"No CLSID specified");
885 return E_INVALIDARG;
886 }
887
889 {
890 PrintHelp(L"No filename specified");
891 return E_INVALIDARG;
892 }
893
894 HRESULT hr;
896 {
899 if (!SUCCEEDED(hr))
900 return hr;
901
902 hr = spSheetExt->AddPages(cb_AddPage, (LPARAM)&g_Pages);
903 if (!SUCCEEDED(hr))
904 {
905 wprintf(L"IShellPropSheetExt->AddPages failed: 0x%x\n", hr);
906 return hr;
907 }
908
909 USHORT ActivePage = HRESULT_CODE(hr);
910 PROPSHEETHEADERW psh = { 0 };
911
912 psh.dwSize = sizeof(psh);
914 psh.pszCaption = L"shlextdbg";
915 psh.phpage = g_Pages.GetData();
916 psh.nPages = g_Pages.GetSize();
917 psh.nStartPage = ActivePage ? (ActivePage-1) : 0;
918 hr = PropertySheetW(&psh);
919
920 wprintf(L"PropertySheetW returned: 0x%x\n", hr);
921 }
922 if (!g_ContextMenu.IsEmpty())
923 {
924 CComPtr<IContextMenu> spContextMenu;
925 hr = LoadAndInitialize(IID_PPV_ARG(IContextMenu, &spContextMenu));
926 if (!SUCCEEDED(hr))
927 return hr;
928
929 // FIXME: Must call QueryContextMenu before InvokeCommand?
930
931 CMINVOKECOMMANDINFO cm = { sizeof(cm), 0 };
932 cm.lpVerb = g_ContextMenu.GetString();
933 cm.nShow = SW_SHOW;
934 hr = spContextMenu->InvokeCommand(&cm);
935
936 if (!SUCCEEDED(hr))
937 {
938 wprintf(L"IContextMenu->InvokeCommand failed: 0x%x\n", hr);
939 return hr;
940 }
941 wprintf(L"IContextMenu->InvokeCommand returned: 0x%x\n", hr);
942 }
943
944 Wait();
945 return 0;
946}
#define UlongToHandle(ul)
Definition: basetsd.h:97
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:904
INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
Definition: propsheet.c:2916
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
const GLint * first
Definition: glext.h:5794
if(dx< 0)
Definition: linetemp.h:194
static UINT UINT last
Definition: font.c:45
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
unsigned short USHORT
Definition: pedump.c:61
#define PSH_PROPTITLE
Definition: prsht.h:40
#define ICC_STANDARD_CLASSES
Definition: commctrl.h:73
#define ICC_LINK_CLASS
Definition: commctrl.h:74
#define SEE_MASK_UNICODE
Definition: shellapi.h:40
#define SEE_MASK_CLASSNAME
Definition: shellapi.h:25
#define SEE_MASK_ASYNCOK
Definition: shellapi.h:43
#define SEE_MASK_IDLIST
Definition: shellapi.h:27
#define SEE_MASK_NOASYNC
Definition: shellapi.h:35
#define SEE_MASK_INVOKEIDLIST
Definition: shellapi.h:28
#define SEE_MASK_FLAG_NO_UI
Definition: shellapi.h:38
#define SEE_MASK_NO_CONSOLE
Definition: shellapi.h:41
VOID WINAPI SHSetInstanceExplorer(LPUNKNOWN lpUnknown)
Definition: shellord.c:1694
BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExW(LPSHELLEXECUTEINFOW sei)
Definition: shlexec.cpp:2552
CStringA g_ContextMenu
Definition: shlextdbg.cpp:430
static BOOL CALLBACK cb_AddPage(HPROPSHEETPAGE page, LPARAM lParam)
Definition: shlextdbg.cpp:631
static void Wait()
Definition: shlextdbg.cpp:604
static IServiceProvider * GetLoggingServiceProvider()
Definition: shlextdbg.cpp:130
static bool isCmdWithArg(int argc, WCHAR **argv, int &n, PCWSTR check, PCWSTR &arg)
Definition: shlextdbg.cpp:641
static bool isCmd(int argc, WCHAR **argv, int n, PCWSTR check)
Definition: shlextdbg.cpp:665
HRESULT LoadAndInitialize(REFIID riid, LPVOID *ppv)
Definition: shlextdbg.cpp:458
bool g_bIShellPropSheetExt
Definition: shlextdbg.cpp:429
static int SHGFI(PCWSTR Path)
Definition: shlextdbg.cpp:268
static HRESULT AssocQ(int argc, WCHAR **argv)
Definition: shlextdbg.cpp:313
DWORD dwSize
Definition: prsht.h:293
DWORD dwFlags
Definition: prsht.h:294
HPROPSHEETPAGE * phpage
Definition: prsht.h:309
UINT nStartPage
Definition: prsht.h:304
LPCWSTR pszCaption
Definition: prsht.h:301
HINSTANCE hInstApp
Definition: shellapi.h:342
HANDLE HINSTANCE
Definition: typedefs.h:77
void * arg
Definition: msvc.h:10
#define SW_SHOWMAXIMIZED
Definition: winuser.h:784
HMENU WINAPI CreatePopupMenu(void)
Definition: menu.c:838
BOOL WINAPI DestroyMenu(_In_ HMENU)
#define SW_SHOW
Definition: winuser.h:786
#define SW_SHOWMINNOACTIVE
Definition: winuser.h:788

Variable Documentation

◆ g_bIShellPropSheetExt

bool g_bIShellPropSheetExt = false

Definition at line 429 of file shlextdbg.cpp.

Referenced by wmain().

◆ g_CLSID

CLSID g_CLSID = { 0 }

Definition at line 426 of file shlextdbg.cpp.

Referenced by LoadAndInitialize(), and wmain().

◆ g_ConsoleWindow

HWND g_ConsoleWindow

Definition at line 531 of file shlextdbg.cpp.

Referenced by EnumWindowsProc(), and WaitWindows().

◆ g_ContextMenu

CStringA g_ContextMenu

Definition at line 430 of file shlextdbg.cpp.

Referenced by wmain().

◆ g_DLL

CStringW g_DLL

Definition at line 427 of file shlextdbg.cpp.

Referenced by LoadAndInitialize(), and wmain().

◆ g_EI

Referenced by Wait(), and wmain().

◆ g_Pages

Definition at line 630 of file shlextdbg.cpp.

Referenced by cb_AddPage(), and wmain().

◆ g_ShellExtInit

CStringW g_ShellExtInit

Definition at line 428 of file shlextdbg.cpp.

Referenced by LoadAndInitialize(), and wmain().

◆ g_Wait

◆ g_Windows

CSimpleArray<HWND> g_Windows

Definition at line 530 of file shlextdbg.cpp.

Referenced by EnumWindowsProc(), and WaitWindows().