Skip to content

Commit

Permalink
I'm not sure what I did wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed May 20, 2020
1 parent d2aab9e commit f314d90
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/cascadia/CascadiaPackage/Package-Dev.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:com="http://schemas.microsoft.com/appx/manifest/com/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
xmlns:uap4="http://schemas.microsoft.com/appx/manifest/uap/windows10/4"
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp rescap">

Expand Down Expand Up @@ -39,7 +42,7 @@
Square150x150Logo="Images\Square150x150Logo.png"
Square44x44Logo="Images\Square44x44Logo.png">
<uap:DefaultTile
Wide310x150Logo="Images\Wide310x150Logo.png"
Wide310x150Logo="Images\Wide310x150Logo.png"
Square71x71Logo="Images\SmallTile.png"
Square310x310Logo="Images\LargeTile.png"
ShortName="ms-resource:AppShortNameDev">
Expand All @@ -58,6 +61,23 @@
<desktop:ExecutionAlias Alias="wtd.exe" />
</uap3:AppExecutionAlias>
</uap3:Extension>

<com:Extension Category="windows.comServer">
<com:ComServer>
<com:SurrogateServer AppId="9f156763-7844-4dc4-bbb1-901f640f5155" DisplayName="WTShellExt">
<com:Class Id="9f156763-7844-4dc4-bbb1-901f640f5155" Path="ShellExtension.dll" ThreadingModel="STA"/>
</com:SurrogateServer>
</com:ComServer>
</com:Extension>
<desktop4:Extension Category="windows.fileExplorerContextMenus">
<desktop4:FileExplorerContextMenus>
<desktop4:ItemType Type=".txt">
<desktop4:Verb Id="Command1" Clsid="9f156763-7844-4dc4-bbb1-901f640f5155" />
</desktop4:ItemType>
</desktop4:FileExplorerContextMenus>
</desktop4:Extension>


</Extensions>

</Application>
Expand Down
76 changes: 76 additions & 0 deletions src/cascadia/ShellExtension/MyShellExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using namespace winrt;
using namespace winrt::Windows::Foundation;

static WCHAR const c_szVerbDisplayName[] = L"ExplorerCommand Verb Sample";
static WCHAR const c_szVerbName[] = L"Sample.ExplorerCommandVerb";

struct MyCoclass : winrt::implements<MyCoclass, IPersist, IStringable, IMyShellExt>
{
HRESULT __stdcall Call() noexcept override
Expand All @@ -22,3 +25,76 @@ struct MyCoclass : winrt::implements<MyCoclass, IPersist, IStringable, IMyShellE
return L"MyCoclass as a string";
}
};

// Agressively copied from
// https://github.com/microsoft/Windows-classic-samples/blob/master/Samples/Win7Samples/winui/shell/appshellintegration/ExplorerCommandVerb/ExplorerCommandVerb.cpp

HRESULT MyShellExt::Invoke(IShellItemArray* /*psiItemArray*/,
IBindCtx* /*pbc*/)
{
return S_OK;
}

HRESULT MyShellExt::GetToolTip(IShellItemArray* /*psiItemArray*/,
LPWSTR* ppszInfotip)
{
// tooltip provided here, in this case none is provieded
*ppszInfotip = NULL;
return E_NOTIMPL;
}
HRESULT MyShellExt::GetTitle(IShellItemArray* /*psiItemArray*/,
LPWSTR* ppszName)
{
// the verb name can be computed here, in this example it is static
return SHStrDup(c_szVerbDisplayName, ppszName);
}
HRESULT MyShellExt::GetState(IShellItemArray* /*psiItemArray*/,
BOOL fOkToBeSlow,
EXPCMDSTATE* pCmdState)
{
// compute the visibility of the verb here, respect "fOkToBeSlow" if this is
// slow (does IO for example) when called with fOkToBeSlow == FALSE return
// E_PENDING and this object will be called back on a background thread with
// fOkToBeSlow == TRUE

*pCmdState = ECS_ENABLED;
return S_OK;

// HRESULT hr;
// if (fOkToBeSlow)
// {
// Sleep(4 * 1000); // simulate expensive work
// *pCmdState = ECS_ENABLED;
// hr = S_OK;
// }
// else
// {
// *pCmdState = ECS_DISABLED;
// // returning E_PENDING requests that a new instance of this object be called back
// // on a background thread so that it can do work that might be slow
// hr = E_PENDING;
// }
// return hr;
}
HRESULT MyShellExt::GetIcon(IShellItemArray* /*psiItemArray*/,
LPWSTR* ppszIcon)
{
// the icon ref ("dll,-<resid>") is provied here, in this case none is provieded
*ppszIcon = NULL;
return E_NOTIMPL;
}
HRESULT MyShellExt::GetFlags(EXPCMDFLAGS* pFlags)
{
*pFlags = ECF_DEFAULT;
return S_OK;
}
HRESULT MyShellExt::GetCanonicalName(GUID* pguidCommandName)
{
*pguidCommandName = __uuidof(this);
return S_OK;
}
HRESULT MyShellExt::EnumSubCommands(IEnumExplorerCommand** ppEnum)
{
*ppEnum = NULL;
return E_NOTIMPL;
}
19 changes: 19 additions & 0 deletions src/cascadia/ShellExtension/MyShellExt.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,22 @@ struct __declspec(uuid("8eb80de0-e1ff-442c-956a-c5f2b54ca274")) IMyShellExt : ::
{
virtual HRESULT __stdcall Call() = 0;
};

struct __declspec(uuid("9f156763-7844-4dc4-bbb1-901f640f5155"))
MyShellExt : winrt::implements<MyShellExt, IExplorerCommand>
{
HRESULT Invoke(IShellItemArray* psiItemArray,
IBindCtx* pbc);
HRESULT GetToolTip(IShellItemArray* psiItemArray,
LPWSTR* ppszInfotip);
HRESULT GetTitle(IShellItemArray* psiItemArray,
LPWSTR* ppszName);
HRESULT GetState(IShellItemArray* psiItemArray,
BOOL fOkToBeSlow,
EXPCMDSTATE* pCmdState);
HRESULT GetIcon(IShellItemArray* psiItemArray,
LPWSTR* ppszIcon);
HRESULT GetFlags(EXPCMDFLAGS* pFlags);
HRESULT GetCanonicalName(GUID* pguidCommandName);
HRESULT EnumSubCommands(IEnumExplorerCommand** ppEnum);
};
1 change: 1 addition & 0 deletions src/cascadia/ShellExtension/ShellExtension.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<DependentUpon>Foo.idl</DependentUpon>
</ClCompile>
<ClCompile Include="MyShellExt.cpp" />
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down
21 changes: 21 additions & 0 deletions src/cascadia/ShellExtension/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "pch.h"
#include "MyShellExt.h"

HRESULT __stdcall DllGetClassObject(GUID const& clsid, GUID const& iid, void** result)
{
try
{
*result = nullptr;

if (clsid == __uuidof(MyShellExt))
{
return winrt::make<MyShellExt>()->QueryInterface(iid, result);
}

return winrt::hresult_class_not_available().to_abi();
}
catch (...)
{
return winrt::to_hresult();
}
}
3 changes: 3 additions & 0 deletions src/cascadia/ShellExtension/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
#include <unknwn.h>
#include <wil/cppwinrt.h>
#include <winrt/Windows.Foundation.h>

#include <Shobjidl.h>
#include <shlwapi.h>

1 comment on commit f314d90

@github-actions

This comment was marked as outdated.

Please sign in to comment.