c++ - 如何强制 MIDL 编译器在 Visual Studio 2010 中使用 "C++ mode"而不是 "C mode"?

标签 c++ visual-studio-2010 com migration midl

我的问题很简单,但我不知道如何解决:我有一个 Visual Studio 2010 项目,其中包含用于生成 COM 类型库的 idl 文件。本项目最初由VC++6.0创建。 VC 6.0 可以编译这个项目,没有任何错误。但我最近转换了它并继续尝试在 VC 2010 中编译它。我总是收到以下控制台输出消息:

1>------ Build started: Project: myProject, Configuration: Debug Win32 ------ 
1>Build started 08.04.2013 11:23:12.
1>InitializeBuildStatus:
1>  Touching ".\Debug\myProject.unsuccessfulbuild".
1>Midl:
1> Processing .\myFile.idl
1>  myProject.idl
1>C:\Programme\Microsoft Visual Studio 10.0\VC\include\typeinfo(29): fatal error C1189: #error :  This header requires a C++ compiler ...
1>
1>midl : command line error MIDL1003: error returned by the C preprocessor (2)
1>
1>Build FAILED.

我已经发现这仅意味着 MIDL 在“C 模式”下调用编译器,而不是在“C++ 模式”下调用编译器。该项目既不包含 .c 也不包含 .cpp,只有 .h 和 .idl 文件:C/C++ 部分在项目属性页中不可用。我尝试添加一个 dummy.cpp 文件,使缺少的部分可用,并能够默认其中的 C++ 编译器。

Midl 文件如下所示:

import "unknwn.idl";

//Globale Definitionen
#include "MyProjectGlobaleDefinitionen.h"

//Interfacedeklarationen

interface IMyProjectDcomSchnittstellen;

[

uuid(E6C14CB3-CFFE-11d4-B1A2-00104BC1A971),
helpstring(MyProject_SCHNITTSTELLE_RELEASE_2_HELPSTRING),
version (MyProject_SCHNITTSTELLE_VERSIONSNUMMER)

]

library MyProject_SCHNITTSTELLE_KURZBEZEICHNER

{

    importlib("..\\..\\..\\Files\\DLL\\stdole32.tlb");
    importlib("..\\..\\..\\Files\\DLL\\MSADO15.dll");

    //  #include "..\..\common\Hresult_Werte.h"
#include "MyProjectDcomSchnittstellenTypdefinitionen.idl"

#include "IObj1ManagerMyProject.idl"
#include "IObj1ManagerMyProjectEvents.idl"

#include "IObj2Manager.idl"
#include "IObj2NotifySink.idl"

    //************ Obj2Manager **************************
    [uuid(F0284CF2-8E24-11d4-8941-006097AA387A)]

        coclass Obj2Manager
    {
        [default] interface IObj2Manager;
        [default, source] interface IObj2NotifySinkEvents;
    }

    //************ Obj1ManagerMyProject ************************
    [uuid(E6C14CB2-CFFE-11d4-B1A2-00104BC1A971)]

        coclass Obj1ManagerMyProject
    {
        [default] interface IObj1ManagerMyProject;
        [default, source] interface IObj1ManagerMyProjectEvents;

    }   
};                                                //Ende library Obj1_myProject

如何强制 MIDL 在“C++ 模式”下调用编译器/预处理器?

最佳答案

不应该

#include "MyProjectDcomSchnittstellenTypdefinitionen.idl"

#include "IObj1ManagerMyProject.idl"
#include "IObj1ManagerMyProjectEvents.idl"

#include "IObj2Manager.idl"
#include "IObj2NotifySink.idl"

原来是这样

import "MyProjectDcomSchnittstellenTypdefinitionen.idl"

import "IObj1ManagerMyProject.idl"
import "IObj1ManagerMyProjectEvents.idl"

import "IObj2Manager.idl"
import "IObj2NotifySink.idl"

好吧...怎么样this一个在这里:

本页仅适用于有特定原因需要将 Microsoft C/C++ 预处理器替换为 MIDL 使用的预处理器的开发人员,或者必须指定自定义预处理器开关的开发人员。 MIDL 开关/cpp_cmd、/cpp_opt 和/no_cpp 用于覆盖编译器的默认行为。通常没有理由替换 Microsoft C/C++ 预处理器,也没有指定自定义预处理器开关。

MIDL 编译器在 IDL 文件的初始处理期间使用 C 预处理器。编译 IDL 文件时使用的构建环境与默认的 C/C++ 预处理器相关联。如果要使用不同的预处理器,MIDL 编译器开关/cpp_cmd 可以覆盖默认的 C/C++ 预处理器名称:

midl /cpp_cmd preprocessor_name filename

关于c++ - 如何强制 MIDL 编译器在 Visual Studio 2010 中使用 "C++ mode"而不是 "C mode"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15876252/

相关文章:

c++ - COM 对象函数上的 API Hook ?

c++ - 反转 vector 并打印它

c# - 无法复制文件“C:\…\packages\…WebApi.Core.4.0.20710.0…System.Web.Http.dll”

c# - 在 Visual Studio 2010 Express 上构建 FreeImage.net

windows - 如何防止 Windows 缓存 Com Class 信息?

c# - 系统.UnauthorizedAccessException : Creating an instance of the COM component fails with error 80070005 (C#)

c++ - C++ allocator::allocate 是否应该抛出?

c++ - while 循环字符 C++

c++ - 将一个右值的元组转换为一个左值的元组

c++ - Octave C++ API (feval) - 如何将多个参数传递给 feval?