Implemented IUnknown part of ExplorerCommand

This commit is contained in:
Ivan Stošić 2022-09-09 11:44:50 +02:00 committed by Ivan Stosic
parent 4969db6229
commit 88aa85e365
6 changed files with 67 additions and 2 deletions

View File

@ -135,10 +135,12 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="ExplorerCommand.h" />
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="ExplorerCommand.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>

View File

@ -18,6 +18,9 @@
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ExplorerCommand.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
@ -26,5 +29,8 @@
<ClCompile Include="pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ExplorerCommand.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,27 @@
#include "pch.h"
#include "ExplorerCommand.h"
IFACEMETHODIMP ExplorerCommand::QueryInterface(REFIID riid, void** ppv)
{
static const QITAB qit[] = {
QITABENT(ExplorerCommand, IExplorerCommand),
{ 0, 0 },
};
return QISearch(this, qit, riid, ppv);
}
IFACEMETHODIMP_(ULONG) ExplorerCommand::AddRef()
{
return ++m_ref_count;
}
IFACEMETHODIMP_(ULONG) ExplorerCommand::Release()
{
auto result = --m_ref_count;
if (result == 0)
{
delete this;
}
return result;
}

View File

@ -0,0 +1,24 @@
#pragma once
#include "pch.h"
class __declspec(uuid("84d68575-e186-46ad-b0cb-baeb45ee29c0")) ExplorerCommand : public IExplorerCommand
{
public:
// IUnknown
IFACEMETHODIMP QueryInterface(REFIID riid, void** ppv);
IFACEMETHODIMP_(ULONG) AddRef();
IFACEMETHODIMP_(ULONG) Release();
// IExplorerCommand
IFACEMETHODIMP GetTitle(IShellItemArray* psiItemArray, LPWSTR* ppszName) override;
IFACEMETHODIMP GetIcon(IShellItemArray* psiItemArray, LPWSTR* ppszIcon) override;
IFACEMETHODIMP GetToolTip(IShellItemArray* psiItemArray, LPWSTR* ppszInfotip) override;
IFACEMETHODIMP GetCanonicalName(GUID* pguidCommandName) override;
IFACEMETHODIMP GetState(IShellItemArray* psiItemArray, BOOL fOkToBeSlow, EXPCMDSTATE* pCmdState) override;
IFACEMETHODIMP Invoke(IShellItemArray* psiItemArray, IBindCtx* pbc) override;
IFACEMETHODIMP GetFlags(EXPCMDFLAGS* pFlags) override;
IFACEMETHODIMP EnumSubCommands(IEnumExplorerCommand** ppEnum) override;
private:
std::atomic<ULONG> m_ref_count;
};

View File

@ -1,6 +1,9 @@
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
// Additional libraries to link
#pragma comment(lib, "shlwapi")
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved

View File

@ -10,8 +10,11 @@
// add headers that you want to pre-compile here
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files
#include <windows.h>
#include <Windows.h>
#include <Shlwapi.h>
#include <ShlObj_core.h>
// C++ Standard library
#include <atomic>
#endif //PCH_H