We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3909

Summary: [WinRT] [Patch] Fix support for C# UWP applications
Product: SDL Reporter: Ethan Lee <flibitijibibo>
Component: mainAssignee: David Ludwig <dll>
Status: RESOLVED FIXED QA Contact: David Ludwig <dll>
Severity: normal    
Priority: P2 CC: dll, slouken
Version: 2.0.6   
Hardware: All   
OS: Windows 10   
Attachments: Move Windows::Foundation::Initialize to SDL2.dll, from SDL_main

Description Ethan Lee 2017-10-22 17:45:36 UTC
Created attachment 3026 [details]
Move Windows::Foundation::Initialize to SDL2.dll, from SDL_main

Attached is a patch that moves Windows::Foundation::Initialize out of the WinMain function into the DLL. Functionally this should be no different for existing applications, but for C# applications this allows us to use SDL2's UWP support by simply calling SDL_WinRTRunApp. Unfortunately we can't call Initialize ourselves from a C# environment, so this seemed like the best solution.

I asked David Ludwig and at first glance he seemed to think it was okay, but WinRT can be a cruel beast... this works for us but I don't know if this somehow violates some obscure UWP rule by not having this call in the EXE. All the docs imply that it should be in WinMain but I don't see anything that explicitly says it's required.
Comment 1 David Ludwig 2017-10-30 23:44:09 UTC
This change looks fine to me, and runs ok on my system.

I also tried testing it against the older, WinRT, WinMain-providing file (Ethan's patch alters it a bit, along with some code in SDL's dll), and it still works ok.
Comment 2 David Ludwig 2017-10-30 23:46:11 UTC
Committed to hg, via https://hg.libsdl.org/SDL/rev/bd1495ebc979

Thanks, Ethan!
Comment 3 Sam Lantinga 2017-11-02 00:35:45 UTC
Thanks!