From fc5982ca8b75bc021d28ff10e6cd99a532966b6b Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 23 Sep 2025 15:01:14 -0500 Subject: [PATCH] Add a WinRT Projection I have not tested this --- src/SearchPlatAPI.sln | 10 + src/projection/FileSearch.cpp | 39 ++++ src/projection/FileSearch.h | 24 ++ src/projection/FileSearch.idl | 13 ++ src/projection/Microsoft.SearchPlatform.def | 3 + .../Microsoft.SearchPlatform.vcxproj | 220 ++++++++++++++++++ src/projection/QueryResult.cpp | 10 + src/projection/QueryResult.h | 21 ++ src/projection/QueryResult.idl | 11 + src/projection/init.cpp | 21 ++ src/projection/packages.config | 17 ++ src/projection/pch.cpp | 4 + src/projection/pch.h | 114 +++++++++ 13 files changed, 507 insertions(+) create mode 100644 src/projection/FileSearch.cpp create mode 100644 src/projection/FileSearch.h create mode 100644 src/projection/FileSearch.idl create mode 100644 src/projection/Microsoft.SearchPlatform.def create mode 100644 src/projection/Microsoft.SearchPlatform.vcxproj create mode 100644 src/projection/QueryResult.cpp create mode 100644 src/projection/QueryResult.h create mode 100644 src/projection/QueryResult.idl create mode 100644 src/projection/init.cpp create mode 100644 src/projection/packages.config create mode 100644 src/projection/pch.cpp create mode 100644 src/projection/pch.h diff --git a/src/SearchPlatAPI.sln b/src/SearchPlatAPI.sln index 7b52591..e863ebd 100644 --- a/src/SearchPlatAPI.sln +++ b/src/SearchPlatAPI.sln @@ -10,6 +10,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "api", "api", "{02EA681E-C7D api\SearchPlatAPI.h = api\SearchPlatAPI.h EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Microsoft.SearchPlatform", "projection\Microsoft.SearchPlatform.vcxproj", "{7615F03F-E56D-4DB4-B23D-AC4FB80DB36F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -26,6 +28,14 @@ Global {E520B4B7-EACC-A761-6E5F-D14F0A095CE4}.Release|x64.Build.0 = Release|x64 {E520B4B7-EACC-A761-6E5F-D14F0A095CE4}.Release|x86.ActiveCfg = Release|Win32 {E520B4B7-EACC-A761-6E5F-D14F0A095CE4}.Release|x86.Build.0 = Release|Win32 + {7615F03F-E56D-4DB4-B23D-AC4FB80DB36F}.Debug|x64.ActiveCfg = Debug|x64 + {7615F03F-E56D-4DB4-B23D-AC4FB80DB36F}.Debug|x64.Build.0 = Debug|x64 + {7615F03F-E56D-4DB4-B23D-AC4FB80DB36F}.Debug|x86.ActiveCfg = Debug|x64 + {7615F03F-E56D-4DB4-B23D-AC4FB80DB36F}.Debug|x86.Build.0 = Debug|x64 + {7615F03F-E56D-4DB4-B23D-AC4FB80DB36F}.Release|x64.ActiveCfg = Release|x64 + {7615F03F-E56D-4DB4-B23D-AC4FB80DB36F}.Release|x64.Build.0 = Release|x64 + {7615F03F-E56D-4DB4-B23D-AC4FB80DB36F}.Release|x86.ActiveCfg = Release|x64 + {7615F03F-E56D-4DB4-B23D-AC4FB80DB36F}.Release|x86.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/projection/FileSearch.cpp b/src/projection/FileSearch.cpp new file mode 100644 index 0000000..780832a --- /dev/null +++ b/src/projection/FileSearch.cpp @@ -0,0 +1,39 @@ +#include "pch.h" +#include "FileSearch.h" +#include "QueryResult.h" +#include "FileSearch.g.cpp" + +using namespace winrt::Windows; + +namespace winrt::Microsoft::SearchPlatform::implementation +{ + // File search provider + FileSearch::FileSearch() + { + } + + FileSearch::~FileSearch() + { + m_searchProvider.reset(); + } + + winrt::Windows::Foundation::Collections::IVector FileSearch::Search(hstring const& query) + { + // Initialize the search platform API + m_searchProvider = std::make_unique(); + m_searchProvider->PrepareForSearch({}, {}); // No included or excluded scopes for now + + std::vector results = m_searchProvider->Search(query.c_str()); + + auto resultVector = winrt::single_threaded_vector(); + for (const auto& result : results) + { + const auto& qr = winrt::make_self(); + qr->_propSet = result.propSet; + qr->_uri = result.uri; + const winrt::Microsoft::SearchPlatform::QueryResult& r = *qr; + resultVector.Append(r); + } + return resultVector; + } +} \ No newline at end of file diff --git a/src/projection/FileSearch.h b/src/projection/FileSearch.h new file mode 100644 index 0000000..ac37c3c --- /dev/null +++ b/src/projection/FileSearch.h @@ -0,0 +1,24 @@ +#pragma once + +#include "FileSearch.g.h" +#include "QueryResult.h" +#include "../api/SearchPlatAPI.h" + +namespace winrt::Microsoft::SearchPlatform::implementation +{ + struct FileSearch : FileSearchT + { + FileSearch(); + ~FileSearch(); + + winrt::Windows::Foundation::Collections::IVector Search(hstring const& query); + + private: + std::unique_ptr m_searchProvider; + }; +} + +namespace winrt::Microsoft::SearchPlatform::factory_implementation +{ + BASIC_FACTORY(FileSearch); +} \ No newline at end of file diff --git a/src/projection/FileSearch.idl b/src/projection/FileSearch.idl new file mode 100644 index 0000000..ab36be4 --- /dev/null +++ b/src/projection/FileSearch.idl @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import "QueryResult.idl"; + +namespace Microsoft.SearchPlatform +{ + runtimeclass FileSearch + { + FileSearch(); + IVector Search(String query); + }; +} \ No newline at end of file diff --git a/src/projection/Microsoft.SearchPlatform.def b/src/projection/Microsoft.SearchPlatform.def new file mode 100644 index 0000000..d04a02e --- /dev/null +++ b/src/projection/Microsoft.SearchPlatform.def @@ -0,0 +1,3 @@ +EXPORTS +DllCanUnloadNow = WINRT_CanUnloadNow PRIVATE +DllGetActivationFactory = WINRT_GetActivationFactory PRIVATE diff --git a/src/projection/Microsoft.SearchPlatform.vcxproj b/src/projection/Microsoft.SearchPlatform.vcxproj new file mode 100644 index 0000000..83895c5 --- /dev/null +++ b/src/projection/Microsoft.SearchPlatform.vcxproj @@ -0,0 +1,220 @@ + + + + ..\ + $(PathToRoot)packages\Microsoft.WindowsAppSDK.1.8.250907003 + + + + + + + + + + + true + true + true + true + {7615F03F-E56D-4DB4-B23D-AC4FB80DB36F} + Microsoft.SearchPlatform + Microsoft.SearchPlatform + en-US + 14.0 + false + Windows Store + 10.0 + 10.0.26100.0 + 10.0.19041.0 + + + + + Debug + ARM64 + + + Debug + x64 + + + Release + ARM64 + + + Release + x64 + + + + $(SolutionDir)$(Platform)\$(Configuration)\WinUI3Apps\CmdPal + obj\$(Platform)\$(Configuration)\ + + + DynamicLibrary + v143 + v142 + v141 + v140 + Unicode + false + true + + + true + true + + + false + true + false + + + + stdcpp20 + + + + MultiThreadedDebug + + + + %(IgnoreSpecificDefaultLibraries);libucrtd.lib + %(AdditionalOptions) /defaultlib:ucrtd.lib /profile /opt:ref /opt:icf + + + + + stdcpp20 + + + + MultiThreaded + + + + %(IgnoreSpecificDefaultLibraries);libucrt.lib + %(AdditionalOptions) /defaultlib:ucrt.lib /profile /opt:ref /opt:icf + + + + + + + + + + + + + + Use + pch.h + $(IntDir)pch.pch + Level4 + %(AdditionalOptions) /bigobj /Zi + _WINRT_DLL;WIN32_LEAN_AND_MEAN;WINRT_LEAN_AND_MEAN;%(PreprocessorDefinitions) + $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) + Guard + Spectre + + + Console + false + Microsoft.SearchPlatform.def + + + + + _DEBUG;%(PreprocessorDefinitions) + ProgramDatabase + + + + + NDEBUG;%(PreprocessorDefinitions) + + + true + true + + + + + %(AdditionalDependencies);user32.lib;shell32.lib + + + + + + QueryResult.idl + + + FileSearch.idl + + + + + + Create + + + QueryResult.idl + + + FileSearch.idl + + + + + + + + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + + + + + + + + + + + diff --git a/src/projection/QueryResult.cpp b/src/projection/QueryResult.cpp new file mode 100644 index 0000000..6923641 --- /dev/null +++ b/src/projection/QueryResult.cpp @@ -0,0 +1,10 @@ +#include "pch.h" +#include "QueryResult.h" +#include "QueryResult.g.cpp" + +using namespace winrt::Windows; + +namespace winrt::Microsoft::SearchPlatform::implementation +{ + // QueryResult implementation (if needed in the future) +} \ No newline at end of file diff --git a/src/projection/QueryResult.h b/src/projection/QueryResult.h new file mode 100644 index 0000000..bf25555 --- /dev/null +++ b/src/projection/QueryResult.h @@ -0,0 +1,21 @@ +#pragma once + +#include "QueryResult.g.h" + +namespace winrt::Microsoft::SearchPlatform::implementation +{ + struct QueryResult : QueryResultT + { + QueryResult() = default; + winrt::Windows::Foundation::Collections::IPropertySet _propSet{ nullptr }; + winrt::hstring _uri; + + winrt::Windows::Foundation::Collections::IPropertySet PropSet() const { return _propSet; } + winrt::hstring Uri() const { return _uri; } + }; +} + +namespace winrt::Microsoft::SearchPlatform::factory_implementation +{ + // BASIC_FACTORY(QueryResult); +} \ No newline at end of file diff --git a/src/projection/QueryResult.idl b/src/projection/QueryResult.idl new file mode 100644 index 0000000..4860fd9 --- /dev/null +++ b/src/projection/QueryResult.idl @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +namespace Microsoft.SearchPlatform +{ + runtimeclass QueryResult + { + Windows.Foundation.Collections.IPropertySet PropSet { get; }; + String Uri { get; }; + }; +} \ No newline at end of file diff --git a/src/projection/init.cpp b/src/projection/init.cpp new file mode 100644 index 0000000..2ea39d4 --- /dev/null +++ b/src/projection/init.cpp @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation +// Licensed under the MIT license. + +#include "pch.h" + +#pragma warning(suppress : 26440) // Not interested in changing the specification of DllMain to make it noexcept given it's an interface to the OS. +BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD reason, LPVOID /*reserved*/) +{ + switch (reason) + { + case DLL_PROCESS_ATTACH: + DisableThreadLibraryCalls(hInstDll); + break; + case DLL_PROCESS_DETACH: + break; + default: + break; + } + + return TRUE; +} diff --git a/src/projection/packages.config b/src/projection/packages.config new file mode 100644 index 0000000..2fb34c8 --- /dev/null +++ b/src/projection/packages.config @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/projection/pch.cpp b/src/projection/pch.cpp new file mode 100644 index 0000000..93c90df --- /dev/null +++ b/src/projection/pch.cpp @@ -0,0 +1,4 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#include "pch.h" diff --git a/src/projection/pch.h b/src/projection/pch.h new file mode 100644 index 0000000..b92edf6 --- /dev/null +++ b/src/projection/pch.h @@ -0,0 +1,114 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +// +// pch.h +// Header for platform projection include files +// + +#pragma once + +#define NOMCX +#define NOHELP +#define NOCOMM + +// Manually include til after we include Windows.Foundation to give it winrt superpowers +#define BLOCK_TIL + +/////////////////////////////////////////////////////////////////////////////////// +// Below is the contents of Terminal's LibraryIncludes.h + +// C +#include +#include +#include + +// STL + +// Block minwindef.h min/max macros to prevent conflict +#define NOMINMAX +// Exclude rarely-used stuff from Windows headers +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// WIL +#include +#include +#include +#include +#include +// Due to the use of RESOURCE_SUPPRESS_STL in result.h, we need to include resource.h first, which happens +// implicitly through the includes above. If RESOURCE_SUPPRESS_STL is gone, the order doesn't matter anymore. +#include +#include + +#define BASIC_FACTORY(typeName) \ + struct typeName : typeName##T \ + { \ + }; + +////////////////////////////////////////////////////////////////////////////////////// + +// This is inexplicable, but for whatever reason, cppwinrt conflicts with the +// SDK definition of this function, so the only fix is to undef it. +// from WinBase.h +// Windows::UI::Xaml::Media::Animation::IStoryboard::GetCurrentTime +#ifdef GetCurrentTime +#undef GetCurrentTime +#endif + +#include + +#include +#include +#include + +#include +#include + +#include +#include +// #include +#include +#include + +// #include + +// Manually include til after we include Windows.Foundation to give it winrt superpowers +//#include "til.h" +#define _TIL_INLINEPREFIX __declspec(noinline) inline +//#include "til_string.h" + +// #include +//#include // must go after the CoreDispatcher type is defined