2013-04-08 32 views
3

我的問題很簡單,但我不知道如何解決它:我有一個Visual Studio 2010項目與idl文件用於生成COM類型庫。該項目最初由VC++ 6.0創建。 VC 6.0可以在沒有任何錯誤的情況下編譯這個項目。但是,我最近轉換,並不斷嘗試編譯它在2010年,我獲得永諾以下控制檯輸出消息VC:如何強制MIDL編譯器在Visual Studio 2010中使用「C++模式」而不是「C模式」?

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++模式」 的編譯器/預處理器?

+0

你錯過了一些東西,消息說'C預處理器',而不是'C編譯器'。你的中檔文件肯定有問題。你能在這裏展示嗎? – 2013-04-08 10:02:36

+0

已更新帖子... Midl內容就在那裏。 – 2013-04-08 10:24:23

+0

看不到任何...?! – 2013-04-08 10:25:16

回答

1

不應該在該

#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 
+0

那是#include語句「太老」了嗎?我只問我,因爲它與Visual Studio 6.0一起工作... – 2013-04-08 10:34:03

+0

好吧,給它一個鏡頭......我沒有看到它在任何地方...... – 2013-04-08 10:35:01

+0

這也失敗了...... :( – 2013-04-08 10:36:42

0

在包含文件MyProjectGlobaleDefinitionen.h有一個包括本。我只需要刪除這個包括,因爲它根本不需要。

相關問題