Skip to content

Commit

Permalink
KozaniManager in-proc WinRT APIs and OOP classic COM APIs to activate…
Browse files Browse the repository at this point in the history
… remote apps (microsoft#3383)

* KozaniManager in-proc WinRT APIs and OOP classic COM APIs to activate remote apps.

Created KozaniManager in-proc WinRT APIs and OOP classic COM APIs to activate remote apps. Added tests to validate the changes.

* Fixed WindowsAppRuntime.sln issue

* Addressed CR feedbacks

* Fixed build issue with x86 and ARM64
  • Loading branch information
rhuang-msft authored Feb 2, 2023
1 parent c0c781b commit 9f4ccfc
Show file tree
Hide file tree
Showing 23 changed files with 409 additions and 33 deletions.
24 changes: 24 additions & 0 deletions WindowsAppRuntime.sln
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Framework.Math.Multiply", "
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Microsoft.WindowsAppRuntime.Framework", "test\DynamicDependency\data\Microsoft.WindowsAppRuntime.Framework\Microsoft.WindowsAppRuntime.Framework.vcxproj", "{9C1A6C58-52D6-4514-9120-5C339C5DF4BE}"
ProjectSection(ProjectDependencies) = postProject
{400ED5EC-4530-4ADB-8DCE-9D1E6708A1F5} = {400ED5EC-4530-4ADB-8DCE-9D1E6708A1F5}
{4410D374-A90C-4ADF-8B15-AA2AAE2636BF} = {4410D374-A90C-4ADF-8B15-AA2AAE2636BF}
{BC5E5A3E-E733-4388-8B00-F8495DA7C778} = {BC5E5A3E-E733-4388-8B00-F8495DA7C778}
EndProjectSection
Expand Down Expand Up @@ -600,7 +601,9 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KozaniManagerRuntimeTests", "test\Kozani\KozaniManagerRuntimeTests\KozaniManagerRuntimeTests.vcxproj", "{4B4667B2-94DB-4A19-8270-0FDB1676C27B}"
ProjectSection(ProjectDependencies) = postProject
{400ED5EC-4530-4ADB-8DCE-9D1E6708A1F5} = {400ED5EC-4530-4ADB-8DCE-9D1E6708A1F5}
{9C1A6C58-52D6-4514-9120-5C339C5DF4BE} = {9C1A6C58-52D6-4514-9120-5C339C5DF4BE}
{B73AD907-6164-4294-88FB-F3C9C10DA1F1} = {B73AD907-6164-4294-88FB-F3C9C10DA1F1}
{D4D29026-C15C-49A3-BEC5-4D477028962C} = {D4D29026-C15C-49A3-BEC5-4D477028962C}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KozaniManagerRuntime", "dev\Kozani\KozaniManagerRuntime\KozaniManagerRuntime.vcxproj", "{400ED5EC-4530-4ADB-8DCE-9D1E6708A1F5}"
Expand All @@ -610,6 +613,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KozaniManagerRuntime", "dev
{CFC67AC3-3DC3-4981-A9BB-BC5ED06542D4} = {CFC67AC3-3DC3-4981-A9BB-BC5ED06542D4}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "data", "data", "{9CE0ED94-078A-405F-8599-BFC2D8D6E537}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KozaniManager.Msix", "test\Kozani\data\KozaniManager.Msix\KozaniManager.Msix.vcxproj", "{D4D29026-C15C-49A3-BEC5-4D477028962C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -2158,6 +2165,21 @@ Global
{400ED5EC-4530-4ADB-8DCE-9D1E6708A1F5}.Release|x64.Build.0 = Release|x64
{400ED5EC-4530-4ADB-8DCE-9D1E6708A1F5}.Release|x86.ActiveCfg = Release|Win32
{400ED5EC-4530-4ADB-8DCE-9D1E6708A1F5}.Release|x86.Build.0 = Release|Win32
{D4D29026-C15C-49A3-BEC5-4D477028962C}.Debug|Any CPU.ActiveCfg = Debug|x64
{D4D29026-C15C-49A3-BEC5-4D477028962C}.Debug|Any CPU.Build.0 = Debug|x64
{D4D29026-C15C-49A3-BEC5-4D477028962C}.Debug|ARM64.ActiveCfg = Debug|x64
{D4D29026-C15C-49A3-BEC5-4D477028962C}.Debug|ARM64.Build.0 = Debug|x64
{D4D29026-C15C-49A3-BEC5-4D477028962C}.Debug|x64.ActiveCfg = Debug|x64
{D4D29026-C15C-49A3-BEC5-4D477028962C}.Debug|x64.Build.0 = Debug|x64
{D4D29026-C15C-49A3-BEC5-4D477028962C}.Debug|x86.ActiveCfg = Debug|Win32
{D4D29026-C15C-49A3-BEC5-4D477028962C}.Debug|x86.Build.0 = Debug|Win32
{D4D29026-C15C-49A3-BEC5-4D477028962C}.Release|Any CPU.ActiveCfg = Release|x64
{D4D29026-C15C-49A3-BEC5-4D477028962C}.Release|Any CPU.Build.0 = Release|x64
{D4D29026-C15C-49A3-BEC5-4D477028962C}.Release|ARM64.ActiveCfg = Release|x64
{D4D29026-C15C-49A3-BEC5-4D477028962C}.Release|x64.ActiveCfg = Release|x64
{D4D29026-C15C-49A3-BEC5-4D477028962C}.Release|x64.Build.0 = Release|x64
{D4D29026-C15C-49A3-BEC5-4D477028962C}.Release|x86.ActiveCfg = Release|Win32
{D4D29026-C15C-49A3-BEC5-4D477028962C}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2342,6 +2364,8 @@ Global
{357BE857-3E5D-475A-8A03-583F44E6513B} = {9164C50F-E9CA-41BD-BCA9-5F30845FA257}
{4B4667B2-94DB-4A19-8270-0FDB1676C27B} = {357BE857-3E5D-475A-8A03-583F44E6513B}
{400ED5EC-4530-4ADB-8DCE-9D1E6708A1F5} = {49CF5AB7-304F-4C78-A098-A77B2931F64E}
{9CE0ED94-078A-405F-8599-BFC2D8D6E537} = {9164C50F-E9CA-41BD-BCA9-5F30845FA257}
{D4D29026-C15C-49A3-BEC5-4D477028962C} = {9CE0ED94-078A-405F-8599-BFC2D8D6E537}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4B3D7591-CFEC-4762-9A07-ABE99938FB77}
Expand Down
5 changes: 4 additions & 1 deletion dev/Kozani/KozaniManager/KozaniManager.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@
<ProjectReference Include="..\KozaniManagerProxyStub\KozaniManagerProxyStub.vcxproj">
<Project>{CFC67AC3-3DC3-4981-A9BB-BC5ED06542D4}</Project>
</ProjectReference>
<ProjectReference Include="..\KozaniManagerRuntime\KozaniManagerRuntime.vcxproj">
<Project>{400ed5ec-4530-4adb-8dce-9d1e6708a1f5}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down Expand Up @@ -187,4 +190,4 @@
<Error Condition="!Exists('$(RepoRoot)\packages\Microsoft.Windows.CppWinRT.$(MicrosoftWindowsCppWinRTVersion)\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '$(RepoRoot)\packages\Microsoft.Windows.CppWinRT.$(MicrosoftWindowsCppWinRTVersion)\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('$(RepoRoot)\packages\Microsoft.Windows.CppWinRT.$(MicrosoftWindowsCppWinRTVersion)\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(RepoRoot)\packages\Microsoft.Windows.CppWinRT.$(MicrosoftWindowsCppWinRTVersion)\build\native\Microsoft.Windows.CppWinRT.targets'))" />
</Target>
</Project>
</Project>
10 changes: 6 additions & 4 deletions dev/Kozani/KozaniManager/KozaniManager.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="KozaniManager-Constants.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="KozaniManagerActivity.h">
<Filter>Source Files</Filter>
</ClInclude>
Expand All @@ -45,4 +42,9 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>
<ItemGroup>
<ResourceCompile Include="KozaniManager.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
20 changes: 15 additions & 5 deletions dev/Kozani/KozaniManager/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include <wrl\module.h>

#include <windows.applicationmodel.activation.h>

using namespace Microsoft::WRL;

// Implement the LifetimeManager as a classic COM Out-of-Proc server, via WRL
Expand All @@ -22,13 +24,21 @@ static constexpr GUID KozaniManager_guid { PR_KOZANIMANAGER_CLSID_GUID };

struct __declspec(uuid(PR_KOZANIMANAGER_CLSID_STRING)) KozaniManagerImpl WrlFinal : RuntimeClass<RuntimeClassFlags<ClassicCom>, IKozaniManager>
{
STDMETHODIMP Initialize()
STDMETHODIMP ActivateRemoteApplication(
INT32 activationKind,
PCWSTR appUserModelId,
PCWSTR connectionRdpFilePath,
PCWSTR additionalSettingsFilePath,
::IInspectable* activatedEventArgs,
IKozaniStatusCallback* statusCallback,
DWORD associatedLocalProcessId)
{
return S_OK;
}
// TODO: https://task.ms/42882034 temporary code to enable initial testing of the in-proc WinRT API and OOP COM API. Will be replaced with real impl later.
if (statusCallback != nullptr)
{
RETURN_IF_FAILED(statusCallback->OnActivated(associatedLocalProcessId));
}

STDMETHODIMP Shutdown()
{
return S_OK;
}
};
Expand Down
26 changes: 23 additions & 3 deletions dev/Kozani/KozaniManagerInterface/KozaniManagerInterface.idl
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,33 @@

import "oaidl.idl";
import "ocidl.idl";
import "inspectable.idl";

[object]
[uuid(5239c3b0-9e90-11ed-87cd-0800200c9a66)]
[pointer_default(unique)]
interface IKozaniStatusCallback : IInspectable
{
HRESULT OnActivated(DWORD pid);

HRESULT OnActivationFailed(
DWORD errorCode,
[in, string] LPCWSTR errorMessage);

HRESULT OnClosed();
};

[object]
[uuid(5882f14f-f954-4af9-bbeb-a7c1a2a6357e)]
[pointer_default(unique)]
interface IKozaniManager : IUnknown
{
HRESULT Initialize();

HRESULT Shutdown();
HRESULT ActivateRemoteApplication(
INT32 activationKind,
[in, string] LPCWSTR appUserModelId,
[in, string] LPCWSTR connectionRdpFilePath,
[in, string] LPCWSTR additionalSettingsFilePath,
[in] IInspectable* activatedEventArgs,
[in] IKozaniStatusCallback* statusCallback,
DWORD associatedLocalProcessId);
};
11 changes: 8 additions & 3 deletions dev/Kozani/KozaniManagerRuntime/KozaniManagerRuntime.idl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ namespace Microsoft.Kozani.ManagerRuntime
[contract(ManagerRuntimeContract, 1)]
runtimeclass ManagerRuntimeManager
{
/// Get a ManagerRuntime manager for the caller's context.
static ManagerRuntimeManager Open();
static ManagerRuntimeManager Create();

void TODO_ReplaceMeWithRealContent();
void ActivateRemoteApplication(
Windows.ApplicationModel.Activation.ActivationKind activationKind,
String appUserModelId,
String connectionRdpFilePath,
String additionalSettingsFilePath,
Windows.ApplicationModel.Activation.IActivatedEventArgs args, // optional, can be nullptr
IInspectable statusCallback);
};
}
11 changes: 8 additions & 3 deletions dev/Kozani/KozaniManagerRuntime/KozaniManagerRuntime.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{400ED5EC-4530-4ADB-8DCE-9D1E6708A1F5}</ProjectGuid>
<RootNamespace>KozaniManagerRuntime</RootNamespace>
<RootNamespace>Microsoft.Kozani.ManagerRuntime</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<CppWinRTModernIDL>true</CppWinRTModernIDL>
<CppWinRTFastAbi>true</CppWinRTFastAbi>
Expand Down Expand Up @@ -92,7 +92,7 @@
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>(MSBuildThisFileDirectory);$(OutDir)\..\WindowsAppRuntime_DLL;$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(RepoRoot)\dev\common;$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>(MSBuildThisFileDirectory);$(OutDir)..\KozaniManagerProxyStub;$(OutDir)\..\WindowsAppRuntime_DLL;$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(RepoRoot)\dev\common;$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PreprocessorDefinitions>KOZANIMANAGERRUNTIMEDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand Down Expand Up @@ -189,6 +189,11 @@
<AdditionalIncludeDirectories>$(RepoRoot)\dev\Common;$(RepoRoot);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KozaniManagerProxyStub\KozaniManagerProxyStub.vcxproj">
<Project>{cfc67ac3-3dc3-4981-a9bb-bc5ed06542d4}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(RepoRoot)\packages\Microsoft.Windows.CppWinRT.$(MicrosoftWindowsCppWinRTVersion)\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('$(RepoRoot)\packages\Microsoft.Windows.CppWinRT.$(MicrosoftWindowsCppWinRTVersion)\build\native\Microsoft.Windows.CppWinRT.targets')" />
Expand Down Expand Up @@ -218,4 +223,4 @@
<Error Condition="!Exists('$(RepoRoot)\packages\Microsoft.SourceLink.GitHub.$(MicrosoftSourceLinkGitHubVersion)\build\Microsoft.SourceLink.GitHub.props')" Text="$([System.String]::Format('$(ErrorText)', '$(RepoRoot)\packages\Microsoft.SourceLink.GitHub.$(MicrosoftSourceLinkGitHubVersion)\build\Microsoft.SourceLink.GitHub.props'))" />
<Error Condition="!Exists('$(RepoRoot)\packages\Microsoft.SourceLink.GitHub.$(MicrosoftSourceLinkGitHubVersion)\build\Microsoft.SourceLink.GitHub.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(RepoRoot)\packages\Microsoft.SourceLink.GitHub.$(MicrosoftSourceLinkGitHubVersion)\build\Microsoft.SourceLink.GitHub.targets'))" />
</Target>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
<ClCompile Include="M.K.MR.ManagerRuntimeManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Midl Include="$(MSBuildThisFileDirectory)KozaniManagerRuntime.idl" />
Expand Down
29 changes: 24 additions & 5 deletions dev/Kozani/KozaniManagerRuntime/M.K.MR.ManagerRuntimeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,35 @@

#include "M.K.MR.ManagerRuntimeManager.h"

#include "Microsoft.Kozani.ManagerRuntime.ManagerRuntimeManager.g.cpp"
#include "ManagerRuntimeManager.g.cpp"

namespace winrt::Microsoft::Kozani::ManagerRuntime::implementation
{
winrt::Microsoft::Kozani::ManagerRuntime::ManagerRuntimeManager ManagerRuntimeManager::Open()
ManagerRuntimeManager::ManagerRuntimeManager()
{
throw hresult_not_implemented();
m_kozaniManager = wil::CoCreateInstance<KozaniManager, IKozaniManager>(CLSCTX_LOCAL_SERVER);
}
void ManagerRuntimeManager::TODO_ReplaceMeWithRealContent()

winrt::Microsoft::Kozani::ManagerRuntime::ManagerRuntimeManager ManagerRuntimeManager::Create()
{
return winrt::make<winrt::Microsoft::Kozani::ManagerRuntime::implementation::ManagerRuntimeManager>();
}

void ManagerRuntimeManager::ActivateRemoteApplication(
Windows::ApplicationModel::Activation::ActivationKind activationKind,
winrt::hstring appUserModelId,
winrt::hstring connectionRdpFilePath,
winrt::hstring additionalSettingsFilePath,
Windows::ApplicationModel::Activation::IActivatedEventArgs args,
IInspectable statusCallback)
{
throw hresult_not_implemented();
winrt::check_hresult(m_kozaniManager->ActivateRemoteApplication(
static_cast<INT32>(activationKind),
appUserModelId.c_str(),
connectionRdpFilePath.c_str(),
additionalSettingsFilePath.c_str(),
reinterpret_cast<::IInspectable*>(winrt::get_abi(args)),
reinterpret_cast<::IKozaniStatusCallback*>(winrt::get_abi(statusCallback)),
GetCurrentProcessId()));
}
}
19 changes: 15 additions & 4 deletions dev/Kozani/KozaniManagerRuntime/M.K.MR.ManagerRuntimeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@

#pragma once

#include "Microsoft.Kozani.ManagerRuntime.ManagerRuntimeManager.g.h"
#include <KozaniManager_h.h>
#include "ManagerRuntimeManager.g.h"

namespace winrt::Microsoft::Kozani::ManagerRuntime::implementation
{
struct ManagerRuntimeManager : ManagerRuntimeManagerT<ManagerRuntimeManager>
{
ManagerRuntimeManager() = default;
ManagerRuntimeManager();

static winrt::Microsoft::Kozani::ManagerRuntime::ManagerRuntimeManager Open();
void TODO_ReplaceMeWithRealContent();
static winrt::Microsoft::Kozani::ManagerRuntime::ManagerRuntimeManager Create();

void ActivateRemoteApplication(
Windows::ApplicationModel::Activation::ActivationKind activationKind,
winrt::hstring appUserModelId,
winrt::hstring connectionRdpFilePath,
winrt::hstring additionalSettingsFilePath,
Windows::ApplicationModel::Activation::IActivatedEventArgs args,
IInspectable statusCallback);

private:
wil::com_ptr<IKozaniManager> m_kozaniManager;
};
}
namespace winrt::Microsoft::Kozani::ManagerRuntime::factory_implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
<MakeMsixInputs Include="$(OutDir)..\WindowsAppRuntime_DLL\Microsoft.WindowsAppRuntime.dll" />
<MakeMsixInputs Include="$(OutDir)..\WindowsAppRuntime_DLL\Microsoft.WindowsAppRuntime.pdb" />
<MakeMsixInputs Include="$(OutDir)..\WindowsAppRuntime_DLL\Microsoft.Internal.FrameworkUdk.dll" />
<MakeMsixInputs Include="$(OutDir)..\KozaniManagerRuntime\KozaniManagerRuntime.dll" />
<MakeMsixInputs Include="$(OutDir)..\KozaniManagerRuntime\KozaniManagerRuntime.pdb" />
</ItemGroup>
<PropertyGroup>
<PackageCertificateKeyFile>$(RepoTestCertificatePFX)</PackageCertificateKeyFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@
<ActivatableClass ActivatableClassId="Microsoft.Windows.System.EnvironmentManager" ThreadingModel="both" />
</InProcessServer>
</Extension>
<Extension Category="windows.activatableClass.inProcessServer">
<InProcessServer>
<Path>KozaniManagerRuntime.dll</Path>
<ActivatableClass ActivatableClassId="Microsoft.Kozani.ManagerRuntime.ManagerRuntimeManager" ThreadingModel="both" />
</InProcessServer>
</Extension>
<Extension Category="windows.activatableClass.proxyStub">
<ProxyStub ClassId="71201C0F-21E1-4B80-945F-7B0A10F90883">
<Path>PushNotificationsLongRunningTask.ProxyStub.dll</Path>
Expand Down
Loading

0 comments on commit 9f4ccfc

Please sign in to comment.