如何使用midlrt.exe将.idl编译为.winmd? [英] How to use midlrt.exe to compile .idl to .winmd?

查看:264
本文介绍了如何使用midlrt.exe将.idl编译为.winmd?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我需要构建Windows运行时组件作为系统的一部分,该系统已设置为使用 CMake 生成其构建系统。作为准备步骤,我正在尝试在命令行上构建它。

Background: I need to build a Windows Runtime Component as part of a system that's set up to use CMake to generate its build system. As a preparatory step I'm trying to build it on the command line.

从裸机开始-bones .idl文件(MyType.idl)

Starting with a bare-bones .idl file (MyType.idl)

namespace NS
{
    [default_interface]
    runtimeclass MyType
    {
    }
}

我正在尝试使用 midlrt.exe 工具。以下命令行(为了提高可读性而分为几行)

I'm trying to generate a matching .winmd file using the midlrt.exe tool. The following command line (split across several lines for readability)

midlrt
    /metadata_dir "%WindowsSdkDir%References\%WindowsSDKVersion%Windows.Foundation.FoundationContract\3.0.0.0"
    /reference "%WindowsSdkDir%References\%WindowsSDKVersion%Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd"
    /winmd MyType.winmd
    /notlb
    /winrt
    /nomidl
    /nologo
    /enum_class
    /ns_prefix
    /client none
    /server none
    MyType.idl

生成MyType.winmd文件就很好了,但是我不知道为什么。我对 / metadata_dir / reference 选项感到困惑。运行 midlrt / help 提供以下内容:

generates the MyType.winmd file just fine, but I don't know why. I'm particularly confused about the /metadata_dir and /reference options. Running midlrt /help offers the following:

/metadata_dir      Specify one or more directories containing platform metadata files
/reference         Specify one or more WinMD files to import

/ metadata_dir 并没有增加多少(除了一个令人困惑的说法:使用此开关来指定Windows主元数据文件的位置,该文​​件名为windows.winmd。 )。没有关于 /引用的文档。

The official documentation on /metadata_dir doesn't add much to that (other than a confusing remark: "Use this switch to specify the location of the main metadata file for Windows, which is named windows.winmd."). There is no documentation for /reference.

这是我需要帮助的地方:

Here's what I need help with:


  • / metadata_dir 选项需要真的通过什么?如上面的命令行中所使用的,它看起来像是 / reference 选项一部分的冗余复制。

  • 如何确定所需的 /引用列表,包括它们的特定版本,会导致编译器错误。 )?

  • What do I really need to pass for the /metadata_dir option? As used in the command line above it looks like a redundant replication of part of the /reference option. Leaving it out produces compiler errors, though.
  • How do I determine the list of required /references including their particular version(s)?

推荐答案

/ metadata_dir必须告诉MIDLRT在哪里可以找到基础的定义MIDLRT由于历史原因而需要的类型。实际上,该目录必须指向包含winmd的目录,该目录定义了Windows SDK中Windows.Foundation命名空间的类型,但是如果需要,可以使用C:\Windows\System32\WinMetadata。前者很难找到)。显然,您只是想进行测试/实验,因为您会碰巧正在运行的任何操作系统版本。正确的格式如下所示:

/metadata_dir is required to tell MIDLRT where it can find the definitions of foundational types that MIDLRT requires for historical reasons. Practically, this must point to the directory containing the winmd that defines the types from the Windows.Foundation namespace in the Windows SDK, but you can use C:\Windows\System32\WinMetadata if you are in a pinch (as the former is hard to track down). Obviously, you'll only want to do this for testing/experimentation since you'll be at the whim of whatever build of the OS you happen to be running on. The correct form looks something like this:

midlrt sample.idl / metadata_dir C:\Program Files(x86)\Windows Kits\ \10\参考文献\10.0.18362.0\Windows.Foundation.FoundationContract\3.0.0.0

查找此路径很棘手。首先在注册表中找到SDK安装路径。然后选择您要定位的SDK版本。然后找到基础合同的最新版本。您可以在此处查看C ++ / WinRT的工作方式:

Finding this path is tricky. Start by finding the SDK install path in the registry. Then pick the SDK version you wish to target. Then find the latest version of the foundation contract. You can look at how C++/WinRT does this here:

https://github.com/microsoft/xlang/blob/master/src/library/impl/cmd_reader_windows.h

/ reference是一个较新的功能,您可以使用它从winmd导入定义,而不必使用IDL导入/包括定义。这主要是一种优化,因为它往往比包含相应的IDL定义要快得多。

/reference is a newer feature where you can use it to import the definitions from a winmd rather than having to import/include the definitions using IDL. This is mainly an optimization as this tends to be much faster than including the corresponding IDL definitions.

无论是否使用/ reference,您仍需要使用/ metadata_dir用于不同的事物。这与cppwinrt.exe不同,在cppwinrt.exe中,它只有一个统一的-reference标志。

You still need to use /metadata_dir regardless of whether you use /reference as they are used for different things. This is different to cppwinrt.exe where it only has a single harmonized -reference flag.

这篇关于如何使用midlrt.exe将.idl编译为.winmd?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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