Skip to content
Closed
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
42 changes: 42 additions & 0 deletions src/Authoring/WinRT.StubExe/WinRT.StubExe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "pch.h"
#include <windows.h>

typedef int (*__managed__Main)(int, wchar_t*[]);

int wmain(int argc, wchar_t* argv[])
{
wchar_t fileName[MAX_PATH];

// Get the path of the current .exe file (it will be renamed to match the app name)
if (!GetModuleFileNameW(NULL, fileName, MAX_PATH))
{
return GetLastError();
}

int fileNameLength = lstrlenW(fileName);

// Replace the extension (.exe -> .dll)
memcpy(
/* _Dst */ &fileName[fileNameLength - 3 /* "exe" */],
/* _Src */ L"dll",
/* _Size */ sizeof(wchar_t) * 3 /* "dll" */);

// Load the .dll for the app
HMODULE hModule = LoadLibraryW(fileName);

if (!hModule)
{
return GetLastError();
}

// Get the custom main from the native .dll (hardcoded to "__managed__Main")
FARPROC pEntryPoint = GetProcAddress(hModule, "__managed__Main");

if (!pEntryPoint)
{
return GetLastError();
}

// Jump to the custom entry point in the implementation .dll
return ((__managed__Main)pEntryPoint)(argc, argv);
}
98 changes: 98 additions & 0 deletions src/Authoring/WinRT.StubExe/WinRT.StubExe.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<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>
<ProjectConfiguration Include="Debug|ARM64">
<Configuration>Debug</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM64">
<Configuration>Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{47ac26da-15ad-41bf-867b-890ffc45b817}</ProjectGuid>
<RootNamespace>WinRTStubExe</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<UseDebugLibraries Condition="'$(Configuration)' == 'Debug'">true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization Condition="'$(Configuration)' == 'Release'">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" />
<ItemDefinitionGroup Condition="'$(Configuration)' == 'Debug'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EntryPointSymbol>wmainCRTStartup</EntryPointSymbol>
<AdditionalOptions>/DEFAULTLIB:WindowsApp.lib %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>WindowsApp.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)' == 'Release'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you will need to enable a more options here to pass https://github.com/microsoft/binskim

<EntryPointSymbol>wmainCRTStartup</EntryPointSymbol>
<AdditionalOptions>/DEFAULTLIB:WindowsApp.lib %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>WindowsApp.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="pch.cpp" PrecompiledHeader="Create" />
<ClCompile Include="WinRT.StubExe.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
25 changes: 25 additions & 0 deletions src/Authoring/WinRT.StubExe/WinRT.StubExe.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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>{2ca660b5-26af-43dd-9654-4782175ecf94}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="WinRT.StubExe.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions src/Authoring/WinRT.StubExe/pch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "pch.h"
1 change: 1 addition & 0 deletions src/Authoring/WinRT.StubExe/pch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#pragma once
19 changes: 19 additions & 0 deletions src/cswinrt.sln
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinAppSDK", "Projections\Wi
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestLibrary", "Tests\FunctionalTests\TestLibrary\TestLibrary.csproj", "{335D51AC-1DCF-4487-A2BD-34CE2F17B3C4}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinRT.StubExe", "Authoring\WinRT.StubExe\WinRT.StubExe.vcxproj", "{47AC26DA-15AD-41BF-867B-890FFC45B817}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Expand Down Expand Up @@ -732,6 +734,22 @@ Global
{335D51AC-1DCF-4487-A2BD-34CE2F17B3C4}.Release|x64.Build.0 = Release|x64
{335D51AC-1DCF-4487-A2BD-34CE2F17B3C4}.Release|x86.ActiveCfg = Release|x86
{335D51AC-1DCF-4487-A2BD-34CE2F17B3C4}.Release|x86.Build.0 = Release|x86
{47AC26DA-15AD-41BF-867B-890FFC45B817}.Debug|ARM.ActiveCfg = Debug|ARM
{47AC26DA-15AD-41BF-867B-890FFC45B817}.Debug|ARM.Build.0 = Debug|ARM
{47AC26DA-15AD-41BF-867B-890FFC45B817}.Debug|ARM64.ActiveCfg = Debug|ARM64
{47AC26DA-15AD-41BF-867B-890FFC45B817}.Debug|ARM64.Build.0 = Debug|ARM64
{47AC26DA-15AD-41BF-867B-890FFC45B817}.Debug|x64.ActiveCfg = Debug|x64
{47AC26DA-15AD-41BF-867B-890FFC45B817}.Debug|x64.Build.0 = Debug|x64
{47AC26DA-15AD-41BF-867B-890FFC45B817}.Debug|x86.ActiveCfg = Debug|Win32
{47AC26DA-15AD-41BF-867B-890FFC45B817}.Debug|x86.Build.0 = Debug|Win32
{47AC26DA-15AD-41BF-867B-890FFC45B817}.Release|ARM.ActiveCfg = Release|ARM
{47AC26DA-15AD-41BF-867B-890FFC45B817}.Release|ARM.Build.0 = Release|ARM
{47AC26DA-15AD-41BF-867B-890FFC45B817}.Release|ARM64.ActiveCfg = Release|ARM64
{47AC26DA-15AD-41BF-867B-890FFC45B817}.Release|ARM64.Build.0 = Release|ARM64
{47AC26DA-15AD-41BF-867B-890FFC45B817}.Release|x64.ActiveCfg = Release|x64
{47AC26DA-15AD-41BF-867B-890FFC45B817}.Release|x64.Build.0 = Release|x64
{47AC26DA-15AD-41BF-867B-890FFC45B817}.Release|x86.ActiveCfg = Release|Win32
{47AC26DA-15AD-41BF-867B-890FFC45B817}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -777,6 +795,7 @@ Global
{C44DB047-5DF0-4732-98F4-A181D3AD8A7F} = {5ECC38F0-16FD-47E1-B8DC-8C474008AD55}
{7B803846-91AE-4B98-AC93-D3FCFB2DE5AA} = {6D41796B-9904-40B8-BBCB-40B2D1BAE44B}
{335D51AC-1DCF-4487-A2BD-34CE2F17B3C4} = {5ECC38F0-16FD-47E1-B8DC-8C474008AD55}
{47AC26DA-15AD-41BF-867B-890FFC45B817} = {DA5AE0BA-E43D-4282-BC80-807DDE0C22C0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5AE8C9D7-2613-4E1A-A4F2-579BAC28D0A2}
Expand Down