简体   繁体   中英

problems in migrating 32bit application on 64 bit

I am trying to migrate existing c++ 32 code to 64 code on windows7 with visual studio 2010.i never did 64bit compilation before. with the help of internet references i did the setup for 64 bit compilation. like VS2010 with 64 bit compiler etc and other configuration changes. In the preprocessor i removed WIN32 and added WIN64. i have some other pre-processors like OS_WIN_32 and some other which are specific in my code. In the code wherever WIN32 was getting used i added extra condition as || WIN64 this is just to ensure that application should get compiled with win32 as well as win64. When i am trying to compile the code i am getting the compilation error saying

fatal error C1189: #error : Only one of the WIN32 and WIN64 symbols should be defined

this error is coming from the local code where we have a check whether both WIN32 and WIN64 are defined. that code is as shown below.

#if defined WIN32 && defined WIN64
# error Only one of the WIN32 and WIN64 symbols should be defined
#endif

in VS2010 if macros are not enabled then the code inside the macro gets greyed out. in my code also the above error is greyed out. but still i am getting that error.

The code where i added WIN64 is including windows.h. for reference givine it below.

#if defined WIN32 || defined WIN64
#include <windows.h>
#include <process.h>
#endif

So my question is why i am getting this error? shouldnt we add windows.h for 64bit compilation.? i tried by commenting this inclusion but i am getting other errors wrt HANDLE which are used in the code. If i go to WIN32 definition VS2010 is pointing to a definition in windef.h file. This file is present in Microsoft SDKs\\windows\\v7.0A\\include folder ie not my local code. for referance that definition is given below.

#ifndef WIN32
#define WIN32
#endif

So i want to know why compiler is getting both pre-processors WIN32 and WIN64.

Thanks in advance for your help.

You shouldn't define either yourself. The macro's that should be used to check this are

_WIN32 // always defined for Windows apps
_WIN64 // only defined for x64 compilation

These are defined by the compiler (see here ).

Often, the IDE adds the unprefixed macros to the commandline to not let legacy projects which use the non-documented unprefixed versions fail to build. The fact that they work is not a reason to use them, when documented alternatives are present.


It boils down to this:

#ifdef _WIN32
  // We're on Windows, yay!
#ifdef _WIN64
  // We're on x64! Yay!
#else // _WIN64
  // We're on x86 (or perhaps IA64, but that one doesn't matter anymore). Yay!
#endif // _WIN64
#else // _WIN32
  // We're not on Windows, maybe WindowsCE or WindowsPhone stuff, otherwise some other platform
 #endif

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM