可以在同一项目中使用C ++ / CX和C ++ / WinRT吗? [英] Can C++/CX and C++/WinRT be used in the same project?

查看:179
本文介绍了可以在同一项目中使用C ++ / CX和C ++ / WinRT吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本周早些时候,Kenny Kerr 展示了C ++ / WinRT在CppCon 2016上 1 。这是Windows运行时的标准C ++投影,基于现代

Earlier this week, Kenny Kerr presented C++/WinRT at CppCon 20161. It is a Standard C++ projection for the Windows Runtime, based on Modern.

据我了解, C ++ / CX 编译器/ preprocessor / code generator不会接触标准C ++代码,并且由于C ++ / WinRT是标准C ++库,因此我天真的解释是C ++ / CX和C ++ / WinRT都可以在同一项目中使用。

As far as I understand, the C++/CX compiler/preprocessor/code generator doesn't touch Standard C++ code, and with C++/WinRT being a Standard C++ library it is my naïve interpretation, that both C++/CX and C++/WinRT can be used in the same project.

问题:


  • 首先,我的天真的解释正确吗?

  • 如果这样,可以在同一编译单元中使用C ++ / CX和C ++ / WinRT吗?

  • 可以将C ++ / CX和C ++ / WinRT混合到什么粒度,如果它们不能驻留在同一编译单元中?

  • C ++ / WinRT可以使用在同一项目中使用C ++ / CX实现的类型吗? (我预计这将很困难,因为C ++ / WinRT编译器需要从.winmd元数据生成标头,因此对(预)编译器输出有依赖性。)

  • First things first: Is my naïve interpretation correct?
  • If so, can C++/CX and C++/WinRT be used in the same compilation unit?
  • At what granularity can C++/CX and C++/WinRT be mixed, in case they cannot reside in the same compilation unit?
  • Can C++/WinRT consume types implemented with C++/CX in the same project? (I expect this to be difficult, since the C++/WinRT compiler needs to generate headers from the .winmd metadata, so there is a dependency on the (pre-)compiler output.)

如果很重要,这些问题的答案使我可以立即决定如何将C ++ / CX项目推向未来。

In case it matters, answers to those questions allow me to make decisions now on how to move my C++/CX projects into the future.



1 采用Windows运行时标准C ++(在YouTube上)

推荐答案

关于 C ++ / WinRT是否可以使用在同一项目中使用C ++ / CX实现的类型?的问题。

Regarding the question "Can C++/WinRT consume types implemented with C++/CX in the same project?"

答案是是和否。 ref类在同一项目中定义,因为这样的项目必须在启用C ++ / CX的情况下进行编译,因此您的代码可以像使用任何ref类一样简单地使用该类。

The answer is Yes and No. With a 'ref class' defined in the same project, as such a project must be compiled with C++/CX enabled, your code can simply use the class as it can any ref class.

但是,如果您想将'ref class'用作C ++ / Win

However, if you want to consume the 'ref class' as a C++/WinRT projection, the answer is effectively no.

为了获得C ++ / WinRT投影类定义,您需要在元数据上运行cppwinrt.exe编译器以获取RT投影。 'ref class'。那将需要以某种方式获取元数据。您可以建立某种机制来编译 ref class一次,获取winmd,通过mdmerge对其进行处理以将其放入规范形式,在元数据上运行cppwinrt.exe以获得预计的类定义,然后包括生成的标头。

In order to get the C++/WinRT projected class definition, you need to run the cppwinrt.exe compiler over the metadata for the 'ref class'. That would require somehow getting the metadata. You could rig up some mechanism to compile the 'ref class' once, get the winmd, process it through mdmerge to put it in canonical form, run cppwinrt.exe on the metadata to get the projected class definition, then include the generated headers.

或者,您可以编写IDL来描述 ref类,使用MIDLRT将其编译为元数据,然后运行cppwinrt.exe。也不是实际的IMO。

Alternatively, you can write the IDL to describe the 'ref class', compile it to metadata using MIDLRT, then run cppwinrt.exe. Neither is practical IMO.

最合理的选择是像使用C ++ / CX类型一样直接使用ref类,因为定义在同一解决方案中。下一个最实用的解决方案是将类放在一个单独的项目中,对其进行编译以获取winmd,然后从winmd创建标头。这种方法还允许使用 ref类(通过投影)的单独项目无需使用C ++ / CX代码即可构建。

The most reasonable alternative is simply use the ref class as is as a C++/CX type, as the definition is in the same solution. Next most practical solution is put the class in a separate project, compile it getting the winmd, then creating headers from the winmd. This approach also allow the separate project that consumes the 'ref class' (via the projection) to build without use of C++/CX code.

要完全透明,请注意我们的初始版本(现已在 https://github.com/Microsoft/cppwinrt 上提供)不包括cppwinrt.exe编译器本身。相反,它包含C ++ / WinRT头文件,其中包含Windows 10周年更新SDK中定义的所有Windows运行时类型/ API的投影-其中包括通用平台API和所有扩展SDK API。

To be completely transparent, note that our initial release (now available at https://github.com/Microsoft/cppwinrt) does not include the cppwinrt.exe compiler itself. Rather, it contains the C++/WinRT header files containing projections for all Windows Runtime types/APIs defined in the Windows 10 Anniversary Update SDK -- this includes the Universal Platform APIs and all Extension SDK APIs.

这篇关于可以在同一项目中使用C ++ / CX和C ++ / WinRT吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆