更改IDL生成的头文件

发布于 2024-10-14 13:45:31 字数 411 浏览 5 评论 0原文

我正在开发一个旧版 c++ COM 项目,并将其转移到 Visual Studio 2010。在该项目的 IDL 文件中,我必须引用另一个 c++ 项目中的 ODL 文件。我的问题是另一个项目生成其头文件为 $(filename)_h.h。当我的 IDL 文件生成其头文件时,它会生成 ODL 文件名 $filename.h,并且无法引用正确的文件。

换句话说,在我的 IDL 文件(“MyIDLFile.idl”)中,我有一个类似于

import“MyODLFile.odl”

它在生成的文件(“MyIDLFile.h”)中变成

包含“MyODLFile.h”

的语句,当我需要它时, generate

include "MyODLFile_h.h"

如何指定 IDL 在导入语句中生成的文件名?

I'm working on a legacy c++ COM project that I'm moving over to Visual Studio 2010. In the IDL file for this project, I have to reference an ODL file from another c++ project. My problem is that the other project generates its header file as $(filename)_h.h. When my IDL file generates its header file, it generates the ODL filename as $filename.h, and it can't reference the correct file.

In other words, in my IDL file ("MyIDLFile.idl") I have a statement like

import "MyODLFile.odl"

which in the generated file ("MyIDLFile.h") becomes

include "MyODLFile.h"

when I need it to generate

include "MyODLFile_h.h"

How do I specify the file name I want the IDL to generate in an import statement?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葬﹪忆之殇 2024-10-21 13:45:31

我不确定您对导入语句的含义,但您要查找的内容可能可以在项目的属性下找到。转到属性窗口 (Alt-F7),在“配置属性/MIDL/输出”下,您将有机会声明您希望创建的头文件。由于您的项目是旧项目,因此从头文件名中删除“_h”可能会更容易(例如 $(ProjectName).h 而不是 $(ProjectName)_h.h)。请参阅 http://support.microsoft.com/kb/321274 了解更多信息。

I'm not sure what you mean about the import statement, but what you're looking for might be found under the project's Properties. Goto the properties window (Alt-F7) and under "Configuration Properties/MIDL/Output", you'll have the opportunity to declare the Header File which you want it to create. Since your project is legacy, it may be easier to just remove the "_h" from the header file name (e.g. $(ProjectName).h instead of $(ProjectName)_h.h). See http://support.microsoft.com/kb/321274 for a lil more info.

情域 2024-10-21 13:45:31

这是处理 IDL 文件时需要解决的常见问题。好处是有几种方法可以解决这个问题:

  1. 使用 MIDL 编译器的选项来更改
  2. 组件的生成输出层,以便在不同的路径中编译冲突的文件。您还可以控制生成的文件的发布方式。然后,需要包含它的代码可以控制文件的包含位置。

您的最终解决方案可能会使用#1 和#2 中的一些内容。

MIDL 编译器有几个选项< /a> 修改输出文件的名称,或排除输出文件。

直接指定名称:

                         -OUTPUT FILE NAMES-
/cstub filename    Specify client stub file name
/dlldata filename  Specify dlldata file name
/h filename        Specify header file name
/header filename   Specify header file name
/iid filename      Specify interface UUID file name
/proxy filename    Specify proxy file name
/sstub filename    Specify server stub file name
/tlb filename      Specify type library file name

跳过输出文件:

                       -OUTPUT FILE GENERATION-
/client none       Do not generate client files
/server none       Generate no server files
/notlb             Don't generate the tlb file

我个人过去曾使用 /prefix 选项来避免标头的名称冲突。

/no_default_epv    Do not generate a default entry-point vector
/prefix client str Add "str" prefix to client-side entry points
/prefix server str Add "str" prefix to server-side manager routines
/prefix switch str Add "str" prefix to switch routine prototypes
/prefix all str    Add "str" prefix to all routines

这是一个例子:

/prefix client HIDE_

带有方法 foo 的接口将在标头中重命名为 HIDE_foo 。

另一种有效的策略与如何分层目录、构建顺序和发布文件、使用包含路径以及对实际包含进行排序有关。我只习惯使用 dir 文件和 build.exe 的源代码,所以我无法给出任何关于 VS 的工作方式的建议。

This is a common problem to solve when dealing with IDL files. The good thing is that there are a few ways to solve this problem:

  1. The use MIDL compiler's options to change the generated output
  2. Layer your component such that conflicting files are compiled in different paths. You can also control how the generated files are published. Then, code that needs to include it can control where the files are included from.

Your ultimate solution may use a little of #1 and #2.

The MIDL compiler has several options to modify the names of output files, or excluding output files.

Directly specifying names:

                         -OUTPUT FILE NAMES-
/cstub filename    Specify client stub file name
/dlldata filename  Specify dlldata file name
/h filename        Specify header file name
/header filename   Specify header file name
/iid filename      Specify interface UUID file name
/proxy filename    Specify proxy file name
/sstub filename    Specify server stub file name
/tlb filename      Specify type library file name

Skipping output files:

                       -OUTPUT FILE GENERATION-
/client none       Do not generate client files
/server none       Generate no server files
/notlb             Don't generate the tlb file

I personally have used the /prefix option to avoid name collisions of headers in the past.

/no_default_epv    Do not generate a default entry-point vector
/prefix client str Add "str" prefix to client-side entry points
/prefix server str Add "str" prefix to server-side manager routines
/prefix switch str Add "str" prefix to switch routine prototypes
/prefix all str    Add "str" prefix to all routines

This is an example of that:

/prefix client HIDE_

The interface with method foo would be renamed to HIDE_foo in the header.

The other strategy that works is related to how you layer your directories, build order, and publish files, and use include paths, and order the actual includes. I am only used to using sources with dir files, and build.exe, so I can't give any advice how that works with VS.

一花一树开 2024-10-21 13:45:31

这似乎是一个常见问题,我一直无法找到任何好的解决方案,但一种解决方法是在 idl 文件中附加“_i”,例如 EquipmentConstants_i.idl

Microsoft 确实引用了 /header 编译开关,但我没有引用无法让它工作(midl / header 开关)。

This seems to be a common problem, I haven't been able to find any good solution but one workaround is to append a '_i" to your idl files, e.g. EquipmentConstants_i.idl

Microsoft does reference a /header compile switch but I haven't been able to get that to work (midl /header switch).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文