Is Win2D yet available in C++/WinRT?
Asked Answered
C

2

3

I need to use win2D in my cppwinrt project. Using the Win2D sample file as a model I’ve tried to mimic its setup, putting in the package file for win2d from that project, duplicating the custom build step, but I can’t get it to compile. I remember some talk about Win2D being added soon to the standard cppwinrt headers so that it could be accessed like others of these wonderful cppwinrt interfaces. Is this something that might happen soon? Or does anyone have some really specific instructions for using Win2D in the current Visual Studio 2017 environment? I’m in the Insider preview program but haven’t seen anything come up. Thanks.

Cuyp answered 17/3, 2018 at 21:38 Comment(8)
The cppwinrt compiler is included in the Windows 10 Insider Preview SDKs. You can generate headers from the Win2D .winmd file yourself. See this postJapha
Chuck, I was put off by this part of that post: "And I know you’re going to ask and the answer is no, this won’t work with Win2D today because the version of cppwinrt.exe that ships with the Windows SDK has a bug that gets in the way. Our internal builds have supported Win2D for some time and I’m told the next Windows SDK will have the fixes, hopefully later this month." In any event those instructions are not functional as written (to begin with, the "where" command will not find cppwinrt.exe in its present location in the 10.0.17035.0\x86 directory) so I'm a little worried about messing up.Cuyp
Ah, sorry for not seeing that comment. I believe it should be resolved by now in the newer SDKs. where in a Developer Command Prompt for VS 2017 works for me (C:\Program Files (x86)\Windows Kits\10\bin\10.0.17110.0\x86\cppwinrt.exe), likely because I have the VS 2017 (15.7 update) Preview installed with the new SDK integration.Japha
Thanks! I wonder if I'm getting the latest VS previews - here's a dumb question: how does one tell the version of a running VS? Don't see anything obvious. I had thought these preview updates were going to be automatic.Cuyp
Help -> About. The overall production version is 15.7.x for the preview version. 15.6.x for latest release version right now.Japha
Great. Should have been able to find that. I see that my VS is 15.6.0. This will take some more looking.Cuyp
What I really would like is to know when it will be possible to access Win2D using C++/winrt without doing any intimate command line surgery.Cuyp
Generally the plan for C++/WinRT is that the Windows 10 SDK will include the core system headers for convenience, but otherwise you should just run cppwinrt.exe on the winmd for any '3rd party' Windows Runtime things you want projections for.Japha
E
6

Once you have downloaded Win2D and assuming you have the latest RS4 Windows SDK installed, you can simply use cppwinrt to generate the Win2D headers for consumption:

cppwinrt -in lib\uap10.0\Microsoft.Graphics.Canvas.winmd -ref sdk

This will generate a winrt folder that contains the headers that you need to include in order to use Win2D. You will then need to add the parent folder to your include paths and ensure that the Win2D DLL is copied to your package or build output folder.

Excavator answered 20/3, 2018 at 16:49 Comment(8)
Kenny, I think I have downloaded Win2D - have at any rate more than one Win2D.uwp.1.21.0. Using the above command prompt produces an error 0x80070057: Could not resolve metadata specification: lib\uwp10.0\Microsoft.Graphics.Canvas.winmd. I've got the 1.21.0 win2d in packages, as it is in the WIn2D sample file, and the additional includes are set as in the WIn2D sample. I appreciate your suggestions above but they are general. Is there some place where I could find really specific detailed instructions for adding WIn2D capability in this environment?Cuyp
Make sure the path to the winmd is valid, e.g. the relative path is being resolve from the right location. That error message basically means "could not find file". We should have project template support soon that takes care of this for you.Excavator
Project template support! What great news. I may just leave the composition code until later with that hope before me. BTW, I think I have the header files - they were already present in your Win2D sample anyway. I just can't find a way to get them known to my app: #include can't find them, though I've put them in the winrt directory with the others.Cuyp
Kenny- I've been away for a few months completing a Mac App and am back to this project. I was hoping that by this time that project template support for c++/winrt would be appearing in VS but I don't see it in 15.9 Preview 2. Am I missing it or is it just not there yet? Thanks.Cuyp
Thanks - when open the sample using VS 15.9.0 Preview 2.0 I see "Project 'PhotoEditor' could not be loaded because it's missing install components. To fix this launch Visual Studio installer with the following selections: Microsoft.Windows.CppWinRT" But even with the latest VS Installer just downloaded I cannot find any mention of this component in the long list of install options - there must be something I'm missing (my experiences may be useful as a general guide to what happens with newbies to this system).Cuyp
Part of the problem is that the error message apparently refers to a component that has a completely different name in VS Installer. The solution I tried was to choose Modify again but reselecting the Universal Windows Platform Development group. Unfortunately the result is that now VS won't even run my existing project; saying that the project is missing install components and now I should run VS Installer and choose Universal Windows Platform Development. Which is how I got here. This is probably the wrong place to speak of this; I expect to get pounded by StackOverflow.Cuyp
If it's a help: on the advice of Felix Huang I set the system environment variable DoBundleInstallationChecks = false, and now I can open my own project again. But I still can't open Photo Editor, and with that variable set false I don't get any error message either - the project just does not load. Perhaps there is some naming clash regarding components?Cuyp
p.s Felix at VS2017 Community has been very helpful but he notes that he doesn't know anything about cppwinrt, so far can't get to the bottom of of this, and that is why I remain on this page adding so many comments and probably annoying the regular denizens.Cuyp
T
5

As of the recent update, using Newget to install Win2D into a C++/WinRT project will automatically generate the headers and install them in "GeneratedFiles\winrt\"

Travers answered 1/6, 2018 at 12:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.