如何在Stdafx.h中使用Ifdef? [英] How to use Ifdef inside Stdafx.h?
问题描述
我有一个c ++文件 -
Example2_s.c
I have a c++ file-
Example2_s.c
* this ALWAYS GENERATED file contains the RPC server stubs */
/* File created by MIDL compiler version 7.00.0555 */
/* at Fri Aug 14 16:10:46 2015
*/
/* Compiler settings for Example2.idl:
Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 7.00.0555
protocol : dce , ms_ext, app_config, c_ext, robust
error checks: allocation ref bounds_check enum stub_data
VC __declspec() decoration level:
__declspec(uuid()), __declspec(selectany), __declspec(novtable)
DECLSPEC_UUID(), MIDL_INTERFACE()
*/
/* @@MIDL_FILE_HEADING( ) */
#if !defined(_M_IA64) && !defined(_M_AMD64)
#pragma warning( disable: 4049 ) /* more than 64k source lines */
#if _MSC_VER >= 1200
#pragma warning(push)
#endif
#pragma warning( disable: 4211 ) /* redefine extern to static */
#pragma warning( disable: 4232 ) /* dllimport identity*/
#pragma warning( disable: 4024 ) /* array to pointer mapping*/
#pragma warning( disable: 4100 ) /* unreferenced arguments in x86 call */
#pragma optimize("", off )
#include <string.h>
#include "Example2_h.h"
#define TYPE_FORMAT_STRING_SIZE 7
#define PROC_FORMAT_STRING_SIZE 31
#define EXPR_FORMAT_STRING_SIZE 1
#define TRANSMIT_AS_TABLE_SIZE 0
#define WIRE_MARSHAL_TABLE_SIZE 0
typedef struct _Example2_MIDL_TYPE_FORMAT_STRING
{
short Pad;
unsigned char Format[ TYPE_FORMAT_STRING_SIZE ];
} Example2_MIDL_TYPE_FORMAT_STRING;
typedef struct _Example2_MIDL_PROC_FORMAT_STRING
{
short Pad;
unsigned char Format[ PROC_FORMAT_STRING_SIZE ];
} Example2_MIDL_PROC_FORMAT_STRING;
typedef struct _Example2_MIDL_EXPR_FORMAT_STRING
{
long Pad;
unsigned char Format[ EXPR_FORMAT_STRING_SIZE ];
} Example2_MIDL_EXPR_FORMAT_STRING;
static const RPC_SYNTAX_IDENTIFIER _RpcTransferSyntax =
{{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}};
extern const Example2_MIDL_TYPE_FORMAT_STRING Example2__MIDL_TypeFormatString;
extern const Example2_MIDL_PROC_FORMAT_STRING Example2__MIDL_ProcFormatString;
extern const Example2_MIDL_EXPR_FORMAT_STRING Example2__MIDL_ExprFormatString;
/* Standard interface: Example1, ver. 1.0,
GUID={0xd3075f46,0x7b6b,0x4577,{0xad,0x5a,0xa4,0x7e,0x62,0x03,0x11,0x6d}} */
extern const MIDL_SERVER_INFO Example1_ServerInfo;
extern const RPC_DISPATCH_TABLE Example1_v1_0_DispatchTable;
static const RPC_SERVER_INTERFACE Example1___RpcServerInterface =
{
sizeof(RPC_SERVER_INTERFACE),
{{0xd3075f46,0x7b6b,0x4577,{0xad,0x5a,0xa4,0x7e,0x62,0x03,0x11,0x6d}},{1,0}},
{{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}},
(RPC_DISPATCH_TABLE*)&Example1_v1_0_DispatchTable,
0,
0,
0,
&Example1_ServerInfo,
0x04000000
};
RPC_IF_HANDLE Example1_v1_0_s_ifspec = (RPC_IF_HANDLE)& Example1___RpcServerInterface;
extern const MIDL_STUB_DESC Example1_StubDesc;
#if !defined(__RPC_WIN32__)
#error Invalid build platform for this stub.
#endif
#if !(TARGET_IS_NT50_OR_LATER)
#error You need Windows 2000 or later to run this stub because it uses these features:
#error /robust command line switch.
#error However, your C/C++ compilation flags indicate you intend to run this app on earlier systems.
#error This app will fail with the RPC_X_WRONG_STUB_VERSION error.
#endif
static const Example2_MIDL_PROC_FORMAT_STRING Example2__MIDL_ProcFormatString =
{
0,
{
/* Procedure Output */
0x32, /* FC_BIND_PRIMITIVE */
0x48, /* Old Flags: */
/* 2 */ NdrFcLong( 0x0 ), /* 0 */
/* 6 */ NdrFcShort( 0x0 ), /* 0 */
/* 8 */ NdrFcShort( 0x4 ), /* x86 Stack size/offset = 4 */
/* 10 */ NdrFcShort( 0x0 ), /* 0 */
/* 12 */ NdrFcShort( 0x0 ), /* 0 */
/* 14 */ 0x42, /* Oi2 Flags: clt must size, has ext, */
0x1, /* 1 */
/* 16 */ 0x8, /* 8 */
0x1, /* Ext Flags: new corr desc, */
/* 18 */ NdrFcShort( 0x0 ), /* 0 */
/* 20 */ NdrFcShort( 0x0 ), /* 0 */
/* 22 */ NdrFcShort( 0x0 ), /* 0 */
/* Parameter szOutput */
/* 24 */ NdrFcShort( 0x10b ), /* Flags: must size, must free, in, simple ref, */
/* 26 */ NdrFcShort( 0x0 ), /* x86 Stack size/offset = 0 */
/* 28 */ NdrFcShort( 0x4 ), /* Type Offset=4 */
0x0
}
};
static const Example2_MIDL_TYPE_FORMAT_STRING Example2__MIDL_TypeFormatString =
{
0,
{
NdrFcShort( 0x0 ), /* 0 */
/* 2 */
0x11, 0x8, /* FC_RP [simple_pointer] */
/* 4 */
0x22, /* FC_C_CSTRING */
0x5c, /* FC_PAD */
0x0
}
};
static const unsigned short Example1_FormatStringOffsetTable[] =
{
0
};
static const MIDL_STUB_DESC Example1_StubDesc =
{
(void *)& Example1___RpcServerInterface,
MIDL_user_allocate,
MIDL_user_free,
0,
0,
0,
0,
0,
Example2__MIDL_TypeFormatString.Format,
1, /* -error bounds_check flag */
0x50002, /* Ndr library version */
0,
0x700022b, /* MIDL Version 7.0.555 */
0,
0,
0, /* notify & notify_flag routine table */
0x1, /* MIDL flag */
0, /* cs routines */
0, /* proxy/server info */
0
};
static const RPC_DISPATCH_FUNCTION Example1_table[] =
{
NdrServerCall2,
0
};
static const RPC_DISPATCH_TABLE Example1_v1_0_DispatchTable =
{
1,
(RPC_DISPATCH_FUNCTION*)Example1_table
};
static const SERVER_ROUTINE Example1_ServerRoutineTable[] =
{
(SERVER_ROUTINE)Output
};
static const MIDL_SERVER_INFO Example1_ServerInfo =
{
&Example1_StubDesc,
Example1_ServerRoutineTable,
Example2__MIDL_ProcFormatString.Format,
Example1_FormatStringOffsetTable,
0,
0,
0,
0};
#pragma optimize("", on )
#if _MSC_VER >= 1200
#pragma warning(pop)
#endif
#endif /* !defined(_M_IA64) && !defined(_M_AMD64)*/
当我编译它时,我要求在我的代码中插入#includestdafx.h。当我这样做时,它向我显示了很多链接错误我知道stdafx.h需要成为第一线。经过一些谷歌搜索,我想包括#if!定义(_M_IA64)&& !在我的stdafx.h文件中定义(_M_AMD64)。但它也没有用。有什么建议吗?
stdafx.h -
When i compile it asks me to insert the #include"stdafx.h" in my code.When i do that it shows me a lot of linking errors.I know that "stdafx.h" need to be the 1st line. After some googling i thought to include the #if !defined(_M_IA64) && !defined(_M_AMD64) in my stdafx.h file. But then also it didnot work. Any suggestions?
"stdafx.h"-
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
//#if !defined(_M_IA64) && !defined(_M_AMD64)
#pragma warning( disable: 4049 )
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
请告诉我为什么当我将stdafx.h置于所有行之上并且如果可能的话建议解决方案时程序是否工作。
Please tell me Why did not the program work when i placed the stdafx.h above all lines and suggest a solution if possible.
推荐答案
我很确定不是编译器要求你插入stdafx.h include而是预编译头管理。
默认情况下,在VisualStudio中,任何新的C / C ++文件使用以下设置添加到项目中:使用预编译的标题。
更改每个C / C +的设置+文件,不需要stdafx.h文件不要使用预编译的头。
如果你想保留stdafx.h文件,你必须请确保:
- 任何#if / #ifdef / #ifndef有#endif
插入#includestdafx.h 位于C / C ++文件的顶部。
I'm quite sure it is not the compiler which ask you to insert the stdafx.h include but the precompiled header management.
By default, in VisualStudio, any new C/C++ file is added to the project with the settings: Use precompiled header.
Change the settings on each C/C++ file which do not need the stdafx.h file with "Do not use precompiled header".
If you want to keep the stdafx.h file, you have to be sure that :
- any #if/#ifdef/#ifndef has its #endif
insert the #include "stdafx.h" at the top of your C/C++ files.
这篇关于如何在Stdafx.h中使用Ifdef?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!