Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
715 changes: 715 additions & 0 deletions samples/ContentDecryptionModule01/ContentDecryption.h

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions samples/ContentDecryptionModule01/ContentDecryptionModule01.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include <iostream>

#include <windows.h>
#include <shlwapi.h>

#pragma comment(lib, "shlwapi.lib")

#include <mfapi.h>
#include <mfidl.h>
#include <mferror.h>
#include <mfmediaengine.h>
#include <mfcontentdecryptionmodule.h>
#include <AudioSessionTypes.h>

#pragma comment(lib, "mfplat.lib")
#pragma comment(lib, "mfuuid.lib")

#include <unknwn.h>
#include <winrt\base.h>

#include <wil\resource.h>
#include <wil\com.h>
#include <wil\token_helpers.h>

#include "Helper.h"
#include "ContentDecryption.h"

wchar_t constexpr const g_Location[] = L"https://test.playready.microsoft.com/media/test/cbcs/bbb.main.30fps.1920x1080.h264.aac.cbcs.sameKeys.mp4";

// <WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="4.3.0.0">
// <DATA><LA_URL>https://test.playready.microsoft.com/core/rightsmanager.asmx?cfg=(playenablers:(786627d8-c2a6-44be-8f88-08ae255b01a7),sl:150,ck:W31bfVt9W31bfVt9W31bfQ==,ckt:AES128BitCBC)</LA_URL>
// <PROTECTINFO><KIDS><KID ALGID="AESCBC" VALUE="AAAAEAAQABAQABAAAAAAAQ=="></KID></KIDS></PROTECTINFO>
// </DATA>
// </WRMHEADER>
uint8_t constexpr const g_InitializationData[]
{
0x00, 0x00, 0x03, 0x54, 0x70, 0x73, 0x73, 0x68, 0x00, 0x00, 0x00, 0x00, 0x9a, 0x04, 0xf0, 0x79, 0x98, 0x40, 0x42, 0x86, 0xab, 0x92, 0xe6, 0x5b, 0xe0, 0x88, 0x5f, 0x95, 0x00, 0x00, 0x03, 0x34, 0x34, 0x03, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x2a, 0x03, 0x3c, 0x00, 0x57, 0x00, 0x52, 0x00, 0x4d, 0x00, 0x48, 0x00, 0x45, 0x00, 0x41, 0x00, 0x44, 0x00, 0x45, 0x00, 0x52, 0x00, 0x20, 0x00, 0x78, 0x00, 0x6d, 0x00, 0x6c, 0x00, 0x6e, 0x00, 0x73, 0x00, 0x3d, 0x00, 0x22, 0x00, 0x68, 0x00, 0x74, 0x00, 0x74, 0x00, 0x70, 0x00, 0x3a, 0x00, 0x2f, 0x00, 0x2f, 0x00, 0x73, 0x00, 0x63, 0x00, 0x68, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x61, 0x00, 0x73, 0x00, 0x2e, 0x00, 0x6d, 0x00, 0x69, 0x00, 0x63, 0x00, 0x72, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x6f, 0x00, 0x66, 0x00, 0x74, 0x00, 0x2e, 0x00, 0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x2f, 0x00, 0x44, 0x00, 0x52, 0x00, 0x4d, 0x00, 0x2f, 0x00, 0x32, 0x00, 0x30, 0x00, 0x30, 0x00, 0x37, 0x00, 0x2f, 0x00, 0x30, 0x00, 0x33, 0x00, 0x2f, 0x00, 0x50, 0x00, 0x6c, 0x00, 0x61, 0x00, 0x79, 0x00, 0x52, 0x00, 0x65, 0x00, 0x61, 0x00, 0x64, 0x00, 0x79, 0x00, 0x48, 0x00, 0x65, 0x00, 0x61, 0x00, 0x64, 0x00, 0x65, 0x00, 0x72, 0x00, 0x22, 0x00, 0x20, 0x00, 0x76, 0x00, 0x65, 0x00, 0x72, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6f, 0x00, 0x6e, 0x00, 0x3d, 0x00, 0x22, 0x00, 0x34, 0x00, 0x2e, 0x00, 0x33, 0x00, 0x2e, 0x00, 0x30, 0x00, 0x2e, 0x00, 0x30, 0x00, 0x22, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x44, 0x00, 0x41, 0x00, 0x54, 0x00, 0x41, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x4c, 0x00, 0x41, 0x00, 0x5f, 0x00, 0x55, 0x00, 0x52, 0x00, 0x4c, 0x00, 0x3e, 0x00, 0x68, 0x00, 0x74, 0x00, 0x74, 0x00, 0x70, 0x00, 0x73, 0x00, 0x3a, 0x00, 0x2f, 0x00, 0x2f, 0x00, 0x74, 0x00, 0x65, 0x00, 0x73, 0x00, 0x74, 0x00, 0x2e, 0x00, 0x70, 0x00, 0x6c, 0x00, 0x61, 0x00, 0x79, 0x00, 0x72, 0x00, 0x65, 0x00, 0x61, 0x00, 0x64, 0x00, 0x79, 0x00, 0x2e, 0x00, 0x6d, 0x00, 0x69, 0x00, 0x63, 0x00, 0x72, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x6f, 0x00, 0x66, 0x00, 0x74, 0x00, 0x2e, 0x00, 0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x2f, 0x00, 0x63, 0x00, 0x6f, 0x00, 0x72, 0x00, 0x65, 0x00, 0x2f, 0x00, 0x72, 0x00, 0x69, 0x00, 0x67, 0x00, 0x68, 0x00, 0x74, 0x00, 0x73, 0x00, 0x6d, 0x00, 0x61, 0x00, 0x6e, 0x00, 0x61, 0x00, 0x67, 0x00, 0x65, 0x00, 0x72, 0x00, 0x2e, 0x00, 0x61, 0x00, 0x73, 0x00, 0x6d, 0x00, 0x78, 0x00, 0x3f, 0x00, 0x63, 0x00, 0x66, 0x00, 0x67, 0x00, 0x3d, 0x00, 0x28, 0x00, 0x70, 0x00, 0x6c, 0x00, 0x61, 0x00, 0x79, 0x00, 0x65, 0x00, 0x6e, 0x00, 0x61, 0x00, 0x62, 0x00, 0x6c, 0x00, 0x65, 0x00, 0x72, 0x00, 0x73, 0x00, 0x3a, 0x00, 0x28, 0x00, 0x37, 0x00, 0x38, 0x00, 0x36, 0x00, 0x36, 0x00, 0x32, 0x00, 0x37, 0x00, 0x64, 0x00, 0x38, 0x00, 0x2d, 0x00, 0x63, 0x00, 0x32, 0x00, 0x61, 0x00, 0x36, 0x00, 0x2d, 0x00, 0x34, 0x00, 0x34, 0x00, 0x62, 0x00, 0x65, 0x00, 0x2d, 0x00, 0x38, 0x00, 0x66, 0x00, 0x38, 0x00, 0x38, 0x00, 0x2d, 0x00, 0x30, 0x00, 0x38, 0x00, 0x61, 0x00, 0x65, 0x00, 0x32, 0x00, 0x35, 0x00, 0x35, 0x00, 0x62, 0x00, 0x30, 0x00, 0x31, 0x00, 0x61, 0x00, 0x37, 0x00, 0x29, 0x00, 0x2c, 0x00, 0x73, 0x00, 0x6c, 0x00, 0x3a, 0x00, 0x31, 0x00, 0x35, 0x00, 0x30, 0x00, 0x2c, 0x00, 0x63, 0x00, 0x6b, 0x00, 0x3a, 0x00, 0x57, 0x00, 0x33, 0x00, 0x31, 0x00, 0x62, 0x00, 0x66, 0x00, 0x56, 0x00, 0x74, 0x00, 0x39, 0x00, 0x57, 0x00, 0x33, 0x00, 0x31, 0x00, 0x62, 0x00, 0x66, 0x00, 0x56, 0x00, 0x74, 0x00, 0x39, 0x00, 0x57, 0x00, 0x33, 0x00, 0x31, 0x00, 0x62, 0x00, 0x66, 0x00, 0x51, 0x00, 0x3d, 0x00, 0x3d, 0x00, 0x2c, 0x00, 0x63, 0x00, 0x6b, 0x00, 0x74, 0x00, 0x3a, 0x00, 0x41, 0x00, 0x45, 0x00, 0x53, 0x00, 0x31, 0x00, 0x32, 0x00, 0x38, 0x00, 0x42, 0x00, 0x69, 0x00, 0x74, 0x00, 0x43, 0x00, 0x42, 0x00, 0x43, 0x00, 0x29, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0x4c, 0x00, 0x41, 0x00, 0x5f, 0x00, 0x55, 0x00, 0x52, 0x00, 0x4c, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x50, 0x00, 0x52, 0x00, 0x4f, 0x00, 0x54, 0x00, 0x45, 0x00, 0x43, 0x00, 0x54, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x46, 0x00, 0x4f, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x4b, 0x00, 0x49, 0x00, 0x44, 0x00, 0x53, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x4b, 0x00, 0x49, 0x00, 0x44, 0x00, 0x20, 0x00, 0x41, 0x00, 0x4c, 0x00, 0x47, 0x00, 0x49, 0x00, 0x44, 0x00, 0x3d, 0x00, 0x22, 0x00, 0x41, 0x00, 0x45, 0x00, 0x53, 0x00, 0x43, 0x00, 0x42, 0x00, 0x43, 0x00, 0x22, 0x00, 0x20, 0x00, 0x56, 0x00, 0x41, 0x00, 0x4c, 0x00, 0x55, 0x00, 0x45, 0x00, 0x3d, 0x00, 0x22, 0x00, 0x41, 0x00, 0x41, 0x00, 0x41, 0x00, 0x41, 0x00, 0x45, 0x00, 0x41, 0x00, 0x41, 0x00, 0x51, 0x00, 0x41, 0x00, 0x42, 0x00, 0x41, 0x00, 0x51, 0x00, 0x41, 0x00, 0x42, 0x00, 0x41, 0x00, 0x41, 0x00, 0x41, 0x00, 0x41, 0x00, 0x41, 0x00, 0x41, 0x00, 0x41, 0x00, 0x51, 0x00, 0x3d, 0x00, 0x3d, 0x00, 0x22, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0x4b, 0x00, 0x49, 0x00, 0x44, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0x4b, 0x00, 0x49, 0x00, 0x44, 0x00, 0x53, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0x50, 0x00, 0x52, 0x00, 0x4f, 0x00, 0x54, 0x00, 0x45, 0x00, 0x43, 0x00, 0x54, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x46, 0x00, 0x4f, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0x44, 0x00, 0x41, 0x00, 0x54, 0x00, 0x41, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0x57, 0x00, 0x52, 0x00, 0x4d, 0x00, 0x48, 0x00, 0x45, 0x00, 0x41, 0x00, 0x44, 0x00, 0x45, 0x00, 0x52, 0x00, 0x3e, 0x00,
};

struct Application : winrt::implements<Application, IUnknown>
{
static std::wstring StoragePath()
{
wchar_t Path[MAX_PATH];
WI_VERIFY(ExpandEnvironmentStringsW(L"%TEMP%", Path, static_cast<DWORD>(std::size(Path)))); // %LOCALAPPDATA%, %USERPROFILE%
WI_VERIFY(PathCombineW(Path, Path, L"ContentDecryptionModule01"));
return Path;
}
void HandleKeySessionMessage(MF_MEDIAKEYSESSION_MESSAGETYPE Type, std::vector<uint8_t> const& Data, std::wstring const& Location)
{
std::wcout << L"HandleKeySessionMessage" << std::endl;
}
void Main()
{
Eme::FactoryConfiguration Configuration { };
Configuration.StoragePath = StoragePath();
std::wcout << L"Configuration.StoragePath: " << Configuration.StoragePath << std::endl;
CreateDirectoryW(Configuration.StoragePath.c_str(), nullptr);
Eme::Factory Factory(Configuration);

// NOTE: This is equivalent to JS
// Navigator.requestMediaKeySystemAccess("com.microsoft.playready.recommendation", [{ initDataTypes: ['cenc'], persistentState: 'optional', distinctiveIdentifier: 'required'])
std::vector<Eme::MediaKeySystemConfiguration> MediaKeySystemConfigurationVector(1);
auto& MediaKeySystemConfiguration = MediaKeySystemConfigurationVector[0];
MediaKeySystemConfiguration.InitDataTypeVector.emplace_back(L"cenc");
MediaKeySystemConfiguration.PersistentState = MF_MEDIAKEYS_REQUIREMENT_OPTIONAL;
MediaKeySystemConfiguration.DistinctiveIdentifier = MF_MEDIAKEYS_REQUIREMENT_REQUIRED;
auto const KeySystemAccess = Factory.RequestMediaKeySystemAccess(L"com.microsoft.playready.recommendation", MediaKeySystemConfigurationVector);
THROW_HR_IF_MSG(MF_E_UNSUPPORTED_SERVICE, !KeySystemAccess, "PlayReady key system configuration is not supported");

auto const MediaKeys = KeySystemAccess->CreateMediaKeys();
MediaKeySession = MediaKeys->CreateSession();
MediaKeySession->OnMessage = [&, StrongThis = get_strong()] (MF_MEDIAKEYSESSION_MESSAGETYPE Type, std::vector<uint8_t> const& Data, std::wstring const& Location) { HandleKeySessionMessage(Type, Data, Location); };
try
{
std::wcout << L"Before GenerateRequest" << std::endl;
MediaKeySession->GenerateRequest(L"cenc", std::vector<uint8_t>(g_InitializationData, g_InitializationData + std::size(g_InitializationData)));
std::wcout << L"After GenerateRequest" << std::endl;
}
catch(...)
{
wchar_t Text[128];
swprintf_s(Text, L"0x%08X", wil::ResultFromCaughtException());
std::wcout << L"After GenerateRequest: " << Text << std::endl;
}
}

std::shared_ptr<Eme::MediaKeySession> MediaKeySession;
};

int wmain()
{
try
{
winrt::init_apartment();
THROW_IF_FAILED(MFStartup(MF_VERSION));
auto&& Scope = wil::scope_exit([] { THROW_IF_FAILED(MFShutdown()); });
auto const Application = winrt::make_self<::Application>();
Application->Main();
}
CATCH_RETURN_MSG("Fatal");
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version='1.0' encoding='utf-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
</assembly>
Binary file not shown.
31 changes: 31 additions & 0 deletions samples/ContentDecryptionModule01/ContentDecryptionModule01.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34221.43
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ContentDecryptionModule01", "ContentDecryptionModule01.vcxproj", "{D08CB923-7F94-49C5-B177-3491B367A4E6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D08CB923-7F94-49C5-B177-3491B367A4E6}.Debug|x64.ActiveCfg = Debug|x64
{D08CB923-7F94-49C5-B177-3491B367A4E6}.Debug|x64.Build.0 = Debug|x64
{D08CB923-7F94-49C5-B177-3491B367A4E6}.Debug|x86.ActiveCfg = Debug|Win32
{D08CB923-7F94-49C5-B177-3491B367A4E6}.Debug|x86.Build.0 = Debug|Win32
{D08CB923-7F94-49C5-B177-3491B367A4E6}.Release|x64.ActiveCfg = Release|x64
{D08CB923-7F94-49C5-B177-3491B367A4E6}.Release|x64.Build.0 = Release|x64
{D08CB923-7F94-49C5-B177-3491B367A4E6}.Release|x86.ActiveCfg = Release|Win32
{D08CB923-7F94-49C5-B177-3491B367A4E6}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {ED1807E3-7D63-413A-AC97-77CE440C0AAA}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.props')" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{d08cb923-7f94-49c5-b177-3491b367a4e6}</ProjectGuid>
<RootNamespace>ContentDecryptionModule01</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<UseDebugLibraries Condition="'$(Configuration)'=='Debug'">true</UseDebugLibraries>
<WholeProgramOptimization Condition="'$(Configuration)'!='Debug'">true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>%(PreprocessorDefinitions);_CONSOLE</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Platform)'=='Win32'">%(PreprocessorDefinitions);WIN32</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Configuration)'=='Debug'">%(PreprocessorDefinitions);_DEBUG</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Configuration)'!='Debug'">%(PreprocessorDefinitions);NDEBUG</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>$(SolutionDir)submodule\wil\include;$(SolutionDir)bin\$(Platform)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ContentDecryptionModule01.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ContentDecryption.h" />
<ClInclude Include="Helper.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ContentDecryptionModule01.rc" />
</ItemGroup>
<ItemGroup>
<Manifest Include="ContentDecryptionModule01.manifest" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.targets')" />
<Import Project="packages\Microsoft.Windows.ImplementationLibrary.1.0.231028.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('packages\Microsoft.Windows.ImplementationLibrary.1.0.231028.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.targets'))" />
<Error Condition="!Exists('packages\Microsoft.Windows.ImplementationLibrary.1.0.231028.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Windows.ImplementationLibrary.1.0.231028.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ContentDecryptionModule01.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ContentDecryptionModule01.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
78 changes: 78 additions & 0 deletions samples/ContentDecryptionModule01/Helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#pragma once

#include <string>

struct SourceCodeReference
{
SourceCodeReference(char const* File, int Line, char const* Function) :
File(File),
Line(Line),
Function(Function)
{
}
char const* FileName() const
{
char const* Separator = strrchr(File, '\\');
if(!Separator)
return File;
return Separator + 1;
}

char const* File;
int Line;
char const* Function;
};

struct TraceContext
{
TraceContext(char const* File, int Line, char const* Function) :
m_SourceCodeReference(File, Line, Function)
{
}
explicit TraceContext(SourceCodeReference& SourceCodeReference) :
m_SourceCodeReference(SourceCodeReference)
{
}

void operator () (wchar_t const* Format, ...) const
{
va_list Arguments;
va_start(Arguments, Format);
wchar_t TextA[8u << 10] { };
vswprintf_s(TextA, Format, Arguments);
va_end(Arguments);
wchar_t TextB[8u << 10] { };
swprintf_s(TextB, L"%hs(%d): %hs: ", m_SourceCodeReference.FileName(), m_SourceCodeReference.Line, m_SourceCodeReference.Function);
wcscat_s(TextB, TextA);
OutputDebugStringW(TextB);
}

SourceCodeReference m_SourceCodeReference;
};

#if !defined(NDEBUG) || 1
#define TRACE TraceContext(__FILE__, __LINE__, __FUNCTION__)
#else
#define TRACE(...) 1 ? 0 : std::ignore = std::make_tuple(__VA_ARGS__)
#endif

template <typename ValueType, size_t t_ItemCount>
inline std::string ToString(std::pair<ValueType, char const* const> const (&Items)[t_ItemCount], ValueType Value)
{
auto const Iterator = std::find_if(Items, Items + t_ItemCount, [=] (auto&& Item) { return Item.first == Value; });
return (Iterator != Items + t_ItemCount) ? Iterator->second : std::to_string(Value);
}

inline std::wstring ToString(GUID const& Value)
{
OLECHAR ValueString[40];
WI_VERIFY(StringFromGUID2(Value, ValueString, static_cast<int>(std::size(ValueString))));
return ValueString;
}

template <size_t t_ItemCount>
inline std::wstring ToString(std::pair<GUID const*, wchar_t const* const> const (&Items)[t_ItemCount], GUID const& Value)
{
auto const Iterator = std::find_if(Items, Items + t_ItemCount, [=] (auto&& Item) { return *Item.first == Value; });
return (Iterator != Items + t_ItemCount) ? Iterator->second : ToString(Value);
}
Loading