-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a context menu entry to "Open Windows Terminal here" #6100
Changes from 4 commits
c67b606
d2aab9e
f314d90
f5fdae7
1d6b017
1851535
44c7da6
3c59824
643125f
ad69e3f
ccb7160
b2184fb
bb2713c
ae42447
5b75378
753fcb3
790f679
380ccc5
f54c7f6
4850d0e
11e9d60
b43f6b2
0edda7f
5a0766c
d5dcc37
a42c340
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,84 +3,31 @@ | |
|
||
#include "pch.h" | ||
#include "OpenTerminalHere.h" | ||
// NOTE: All this file is pretty egregiously taken from PowerToys's PowerRename, | ||
// specifically: | ||
|
||
// For reference, see: | ||
// * https://docs.microsoft.com/en-us/cpp/cppcx/wrl/how-to-create-a-classic-com-component-using-wrl?view=vs-2019 | ||
// * https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/move-to-winrt-from-wrl#porting-a-wrl-module-microsoftwrlmodule | ||
// | ||
// https://github.com/microsoft/PowerToys/blob/master/ | ||
// src/modules/powerrename/dll/dllmain.cpp | ||
// We don't need to implement DllGetActivationFactory or DllCanUnloadNow | ||
// manually, since the generated module.g.cpp will handle it for us, and will | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm surprised we get a module.g.cpp . . . did we make sure the cppwinrt WRL hookup works right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we get it because of |
||
// handle our WRL types appropriately. | ||
// | ||
// I'm not positive how much of it we need, but we definitely need: | ||
// * a ClassFactory that can create our implementation of IExplorerCommand | ||
// * a DllGetClassObject that will return the aforementioned class factory. | ||
|
||
std::atomic<DWORD> g_dwModuleRefCount = 0; | ||
HINSTANCE g_hInst = 0; | ||
|
||
extern "C" IMAGE_DOS_HEADER __ImageBase; | ||
void ModuleAddRef() | ||
{ | ||
g_dwModuleRefCount++; | ||
} | ||
// We DO need to implement DllGetClassObject, because that's what explorer.exe | ||
// will call to attempt to create a class factory for our shell extension. The | ||
// CoCreatableClass macro in OpenTerminalHere.h will create the factory for us, | ||
// so that the GetClassObject call will work like magic. | ||
|
||
void ModuleRelease() | ||
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, _COM_Outptr_ void** ppv) | ||
{ | ||
g_dwModuleRefCount--; | ||
return Microsoft::WRL::Module<Microsoft::WRL::InProc>::GetModule().GetClassObject(rclsid, riid, ppv); | ||
} | ||
|
||
struct ShellExtClassFactory : winrt::implements<ShellExtClassFactory, IClassFactory> | ||
STDAPI_(BOOL) | ||
DllMain(_In_opt_ HINSTANCE hinst, DWORD reason, _In_opt_ void*) | ||
{ | ||
public: | ||
ShellExtClassFactory(_In_ REFCLSID clsid) : | ||
m_clsid{ clsid } {}; | ||
|
||
// IClassFactory methods | ||
IFACEMETHODIMP CreateInstance(_In_opt_ IUnknown* punkOuter, | ||
_In_ REFIID riid, | ||
_Outptr_ void** ppv) | ||
if (reason == DLL_PROCESS_ATTACH) | ||
{ | ||
*ppv = NULL; | ||
HRESULT hr; | ||
if (punkOuter) | ||
{ | ||
hr = CLASS_E_NOAGGREGATION; | ||
} | ||
else if (m_clsid == __uuidof(OpenTerminalHere)) | ||
{ | ||
hr = winrt::make<OpenTerminalHere>()->QueryInterface(riid, ppv); | ||
} | ||
else | ||
{ | ||
hr = CLASS_E_CLASSNOTAVAILABLE; | ||
} | ||
return hr; | ||
DisableThreadLibraryCalls(hinst); | ||
} | ||
|
||
IFACEMETHODIMP LockServer(BOOL bLock) | ||
{ | ||
if (bLock) | ||
{ | ||
ModuleAddRef(); | ||
} | ||
else | ||
{ | ||
ModuleRelease(); | ||
} | ||
return S_OK; | ||
} | ||
|
||
private: | ||
CLSID m_clsid; | ||
}; | ||
|
||
// !IMPORTANT! Make sure that DllGetClassObject is exported in <dllName>.def! | ||
HRESULT __stdcall DllGetClassObject(GUID const& clsid, GUID const& iid, void** result) | ||
{ | ||
*result = nullptr; | ||
// !IMPORTANT! Explorer is going to call DllGetClassObject with the clsid of | ||
// the class it wants to create, and the iid of IClassFactory. First we must | ||
// return the ClassFactory here - later on, the ClassFactory will have | ||
// CreateInstance called, where we can actually create the thing it | ||
// requested in clsid. | ||
auto pClassFactory = winrt::make<ShellExtClassFactory>(clsid); | ||
return pClassFactory->QueryInterface(iid, result); | ||
return TRUE; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,6 @@ | |
|
||
#include <Shobjidl.h> | ||
#include <shlwapi.h> | ||
|
||
#include <wrl.h> | ||
#include <wrl\module.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@miniksa @DHowett Okay, how did I mess this up? I thought this was how you un-include a project from audit mode? I really don't think I had anything to do with this error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, maybe the U8U16Test error isn't from this PR - I just checked out master and that can't build it in release either, but I've filed #6220 for this