Targeting both Win32 and UWP

Started by
6 comments, last by GuyWithBeard 5 years, 11 months ago

Hey folks!

I have a question about how I should organize my Visual Studio project and/or solution to allow targeting both Win32 and UWP with as little resistance as possible. Currently my project consists of a game exe project and a few dll projects, all sitting under the same solution, and all targeting plain old Win32 with Visual Studio 2013. I have been thinking about porting the project to UWP for some time now, mainly to be able to run on the Xbox, but there are some things I haven't wrapped my head around, mainly how to organize the projects in Visual Studio.

As far as I know, to build for UWP I would need to update to VS2015 and I would need to make the project an "app container" project. Codewise there shouldn't be that much to do, except change the main loop to work through the CoreApplication system as well as remove some uses of LoadLibrary() etc. However, it seems that if I change the project to an "app container" project I loose the ability to build for Win32. I was hoping I could simply add a new UWP configuration to the solution which would make all projects build "app container" targets, but that does not seem to be possible. Creating a new empty UWP project in VS and opening the vcxproj file up in a text editor reveals things like this in the "Globals" property group:


<AppContainerApplication>true</AppContainerApplication>
<ApplicationType>Windows Store</ApplicationType>
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformMinVersion>10.0.10586.0</WindowsTargetPlatformMinVersion>
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>

Namely, they are not part of a configuration, but instead make the whole project an "app container" project.

What I would like to do is have one project (eg. the exe of the game) where I could flip between Win32 and UWP easily through configurations, using #defines to enable/disable parts of the code that does not apply to the current configuration. Is there a way to do this?

One way I have been thinking about is having the Win32 project be the "main" project and have a UWP project which simply includes links to each and every source file in the Win32 project. This sounds cumbersome and error prone and I would like to avoid it if possible. Another way would be to autogenerate both projects with something like CMake, SharpMake or premake, but I would not want to get into that either right now. Any other options?

Cheers!

Advertisement

They way I did it was to add a "shared project" with the game's main logic and code. Then add a UWP and a Win32 project with the added reference to the shared project.

The UWP and Win32 project respectively only contain the main entry point and a few additional classes required for their platform (like the main game loop)

 

What annoyed me majorly:

Sharing assets. UWP can only load from the project folder itself, so I fudged the Win32 project to have the project folder of the UWP project as working directory. This way I only have the assets around once. Unfortunately right inside the code folders. I would have preferred to have a separate asset folder.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Interesting. Does the shared project produce a library which is then consumed by the other projects, or is it just a container for the shared code in VS?

It's a container of shared code. All the files in the shared project are treated as simply being included in the other projects.

Which also means they're compiled separately for every project that references them.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Sounds like something I should look into. Is this a scenario VS supports directly? Eg. what kind of project is the shared code project? Do you have to make it an actual C++ project (and if so, what kind?) and then just skip building it when building the solution or is there a special project type for these kinds of things?

Thanks!

It's coming with VS 2015 (probably in earlier versions too).

Just create a new project, it's under C++, Generic, Shared Items Project. 

For other projects including this, right click on the project in the Solution Explorer, "Add Reference". There should be an option now, "Shared Projects", set a check mark and you're done.

 

The shared project itself has no build action, it's just a container for the files.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Excellent, yeah it seems like it was added in 2015. There is no such project type in VS 2013. Thanks for your help, I have some stuff to try out now :)

This topic is closed to new replies.

Advertisement