开发者

Change IDL generated header file

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 refe开发者_如何转开发rence 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?


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.


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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜