Skip to content

Commit

Permalink
Add cs example
Browse files Browse the repository at this point in the history
  • Loading branch information
roxk committed Jun 25, 2023
1 parent 847efb9 commit d03f24e
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ obj
packages/
*.user
**/*.assets.cache
Generated Files
Generated Files
*.nupkg
26 changes: 26 additions & 0 deletions AppExtensionCSharp/AppExtensionCSharp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows10.0.22621.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<ImplicitUsings>enable</ImplicitUsings>
<SelfContained>true</SelfContained>
<CsWinRTComponent>true</CsWinRTComponent>
<Platforms>x64</Platforms>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup>
<RestoreSources>
https://api.nuget.org/v3/index.json;
../SDKCsProjection/nuget
</RestoreSources>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SDKCsProjection" Version="0.0.1" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.3" />
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions AppExtensionCSharp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using ABI.Windows.Foundation;
using ABI.WinRT.Interop;
using AppExtensionCSharp;
using Windows.ApplicationModel.Core;
using Windows.Foundation;
using Windows.Graphics.Capture;
using WinRT.Interop;

internal static class Program
{
public static void Main()
{
CoreApplication.RunWithActivationFactories(new ActivationFactoryGetter());
}
}

internal class ActivationFactoryGetter : IGetActivationFactory
{
public object GetActivationFactory(string activatableClassId)
{
return WinRT.Module.GetActivationFactory(activatableClassId);
}
}
18 changes: 18 additions & 0 deletions AppExtensionCSharp/WidgetProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppExtensionCSharp
{
public sealed class WidgetProvider : SDK.IWidgetProvider
{
public WidgetProvider() { }

public string SayHello()
{
return "Greeting from C# Extension!";
}
}
}
4 changes: 3 additions & 1 deletion AppExtensionPackage/AppExtensionPackage.wapproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<DefaultLanguage>en-US</DefaultLanguage>
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
<NoWarn>$(NoWarn);NU1702</NoWarn>
<EntryPointProjectUniqueName>..\AppExtension\AppExtension.vcxproj</EntryPointProjectUniqueName>
<EntryPointProjectUniqueName>..\AppExtensionCSharp\AppExtensionCSharp.csproj</EntryPointProjectUniqueName>
</PropertyGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
Expand All @@ -77,6 +77,8 @@
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AppExtensionCSharp\AppExtensionCSharp.csproj" />
<ProjectReference Include="..\AppExtension\AppExtension.vcxproj" />
<Content Include="..\AppExtensionCSharp\bin\$(Platform)\$(Configuration)\net6.0-windows10.0.22621.0\win10-$(Platform)\AppExtensionCSharp.winmd"/>
</ItemGroup>
</Project>
14 changes: 11 additions & 3 deletions AppExtensionPackage/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,26 @@
<WidgetProvider>
<Activation>
<ActivatableClass ActivatableClassId="PackagedOOPWinRTServerAppExtension.WidgetProvider"/>
<ActivatableClass ActivatableClassId="AppExtensionCSharp.WidgetProvider"/>
</Activation>
</WidgetProvider>
</uap3:Properties>
</uap3:AppExtension>
</uap3:Extension>
<uap5:Extension Category="windows.activatableClass.outOfProcessServer">
<uap5:OutOfProcessServer ServerName="WidgetProviderServer" RunFullTrust="true">
<uap5:OutOfProcessServer ServerName="WidgetProviderCppServer" RunFullTrust="true">
<uap5:Path>AppExtension\AppExtension.exe</uap5:Path>
<uap5:Instancing>singleInstance</uap5:Instancing>
<uap5:ActivatableClass ActivatableClassId="PackagedOOPWinRTServerAppExtension.WidgetProvider" />
</uap5:OutOfProcessServer>
</uap5:Extension>
</uap5:OutOfProcessServer>
</uap5:Extension>
<uap5:Extension Category="windows.activatableClass.outOfProcessServer">
<uap5:OutOfProcessServer ServerName="WidgetProviderCSharpServer" RunFullTrust="true">
<uap5:Path>AppExtensionCSharp\AppExtensionCSharp.exe</uap5:Path>
<uap5:Instancing>singleInstance</uap5:Instancing>
<uap5:ActivatableClass ActivatableClassId="AppExtensionCSharp.WidgetProvider" />
</uap5:OutOfProcessServer>
</uap5:Extension>
</Extensions>
</Application>
</Applications>
Expand Down
64 changes: 49 additions & 15 deletions Host/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,62 @@ wf::IAsyncOperation<int> MainAsync()
std::wcout << L"Could not find activation" << std::endl;
continue;
}
std::vector<winrt::hstring> classIds;
auto activatableClass{ TryGet<wfc::IPropertySet>(activation, L"ActivatableClass") };
if (activatableClass == nullptr)
if (activatableClass != nullptr)
{
std::wcout << L"Could not find activatable class" << std::endl;
continue;
auto classIdOpt{ TryGet<winrt::hstring>(activatableClass, L"@ActivatableClassId") };
if (!classIdOpt)
{
std::wcout << L"Could not find class Id" << std::endl;
continue;
}
classIds.emplace_back(std::move(*classIdOpt));
}
auto classIdOpt{ TryGet<winrt::hstring>(activatableClass, L"@ActivatableClassId") };
if (!classIdOpt)
else
{
std::wcout << L"Could not find class Id" << std::endl;
continue;
auto activatableClasses{ TryGet<wf::IReferenceArray<wf::IInspectable>>(activation, L"ActivatableClass") };
if (activatableClasses == nullptr)
{
std::wcout << L"Could not find any activatable class" << std::endl;
continue;
}
winrt::com_array<wf::IInspectable> classes;
activatableClasses.GetInspectableArray(classes);
if (classes.empty())
{
std::wcout << L"Could not find any activatable class array" << std::endl;
continue;
}
for (auto&& classProp : classes)
{
auto cls{ classProp.try_as<wfc::IPropertySet>() };
if (cls == nullptr)
{
std::wcout << L"An activatable class element isn't a property set" << std::endl;
continue;
}
auto classIdOpt{ TryGet<winrt::hstring>(cls, L"@ActivatableClassId") };
if (!classIdOpt)
{
std::wcout << L"Could not find class Id" << std::endl;
continue;
}
classIds.emplace_back(std::move(*classIdOpt));
}
}
auto classId{ *classIdOpt };
auto factory{ winrt::get_activation_factory(classId)};
auto widgetProvider{ factory.ActivateInstance<winrt::SDK::IWidgetProvider>() };
if (widgetProvider == nullptr)
for (auto&& classId : classIds)
{
std::wcout << L"Extension's activatable class isn't an IWidgetProvider" << std::endl;
continue;
auto factory{ winrt::get_activation_factory(classId) };
auto widgetProvider{ factory.ActivateInstance<winrt::SDK::IWidgetProvider>() };
if (widgetProvider == nullptr)
{
std::wcout << L"Extension's activatable class isn't an IWidgetProvider" << std::endl;
continue;
}
auto hello{ widgetProvider.SayHello() };
std::wcout << L"widget from " << pfn.c_str() << L" saying hello: " << hello.c_str() << std::endl;
}
auto hello{ widgetProvider.SayHello() };
std::wcout << L"widget from " << pfn.c_str() << L" saying hello: " << hello.c_str() << std::endl;
}
co_return 0;
}
Expand Down
22 changes: 22 additions & 0 deletions PackagedOOPWinRTServerAppExtension.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AppExtension", "AppExtensio
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AppExtensionCSharp", "AppExtensionCSharp\AppExtensionCSharp.csproj", "{D4E57DFB-EA15-49A4-B785-39FA3B2F59F7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SDKCsProjection", "SDKCsProjection\SDKCsProjection.csproj", "{476EFFBB-BFBC-4034-ADAD-11986E77B328}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -169,6 +171,26 @@ Global
{D4E57DFB-EA15-49A4-B785-39FA3B2F59F7}.Release|x64.Build.0 = Release|x64
{D4E57DFB-EA15-49A4-B785-39FA3B2F59F7}.Release|x86.ActiveCfg = Release|Any CPU
{D4E57DFB-EA15-49A4-B785-39FA3B2F59F7}.Release|x86.Build.0 = Release|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Debug|Any CPU.Build.0 = Debug|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Debug|ARM.ActiveCfg = Debug|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Debug|ARM.Build.0 = Debug|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Debug|ARM64.Build.0 = Debug|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Debug|x64.ActiveCfg = Release|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Debug|x64.Build.0 = Release|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Debug|x86.ActiveCfg = Debug|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Debug|x86.Build.0 = Debug|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Release|Any CPU.ActiveCfg = Release|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Release|Any CPU.Build.0 = Release|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Release|ARM.ActiveCfg = Release|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Release|ARM.Build.0 = Release|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Release|ARM64.ActiveCfg = Release|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Release|ARM64.Build.0 = Release|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Release|x64.ActiveCfg = Release|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Release|x64.Build.0 = Release|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Release|x86.ActiveCfg = Release|Any CPU
{476EFFBB-BFBC-4034-ADAD-11986E77B328}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion SDK/SDK.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" Condition="Exists('$(GeneratedFilesDir)module.g.cpp')" />
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
8 changes: 8 additions & 0 deletions SDKCsProjection/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project>
<PropertyGroup>
<BuildOutDir>$([MSBuild]::NormalizeDirectory('$(SolutionDir)', '_build', '$(Platform)', '$(Configuration)'))</BuildOutDir>
<OutDir>$([MSBuild]::NormalizeDirectory('$(BuildOutDir)', '$(MSBuildProjectName)', 'bin'))</OutDir>
<IntDir>$([MSBuild]::NormalizeDirectory('$(BuildOutDir)', '$(MSBuildProjectName)', 'obj'))</IntDir>
</PropertyGroup>
</Project>
28 changes: 28 additions & 0 deletions SDKCsProjection/SDKCsProjection.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-windows10.0.22621.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Platform>AnyCPU</Platform>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SDK\SDK.vcxproj" />
</ItemGroup>

<PropertyGroup>
<CsWinRTIncludes>SDK</CsWinRTIncludes>
<CsWinRTGeneratedFilesDir>$(OutDir)</CsWinRTGeneratedFilesDir>
<GeneratedNugetDir>.\nuget\</GeneratedNugetDir>
<NuspecFile>$(GeneratedNugetDir)SDKCsProjection.nuspec</NuspecFile>
<OutputPath>$(GeneratedNugetDir)</OutputPath>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

</Project>
16 changes: 16 additions & 0 deletions SDKCsProjection/nuget/SDKCsProjection.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>SDKCsProjection</id>
<version>0.0.1</version>
<authors>Roxk</authors>
<description>SDK Projection</description>
<dependencies>
<group targetFramework="net6.0-windows10.0.22621.0" />
</dependencies>
</metadata>
<files>
<file src="..\..\_build\AnyCPU\Release\SDKCsProjection\bin\SDKCsProjection.dll" target="lib\net6.0-windows10.0.22621.0\SDKCsProjection.dll" />
<file src="..\..\x64\Release\SDK\SDK.dll" target="runtimes\win10-x64\native\SDK.dll" />
</files>
</package>

0 comments on commit d03f24e

Please sign in to comment.