Solved

Preprocessor definitions

Posted on 2015-02-08
4
109 Views
Last Modified: 2015-02-09
Hi

I have a visual studio projects that I am compiling in Debug mode with x64. However, I noticed that the Preprocessor definitions in Propert Pages->Configuration Properties -> C/C++ -> Preprocessor is WIN32.  Do I need to change this to 64 bit equivalent? What would that equivalent be? And what does this preprocessor definition mean anyway ?

thanks
0
Comment
Question by:LuckyLucks
  • 2
4 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 250 total points
ID: 40597172
WIN32 (ot _WIN32) is a predefined macro (see https://msdn.microsoft.com/en-us/library/vstudio/b0084kay%28v=vs.110%29.aspx - "Predefined Macros" - for a complete list) which MS explains as

_WIN32

Defined for applications for Win32 and Win64. Always defined.

There is also a _WIN64 but you usually don't need to explicitly set it, the compiler will do that when building x64 binaries.
0
 
LVL 33

Accepted Solution

by:
sarabande earned 250 total points
ID: 40598963
to add to before comment:

_WIN32 was used in various header files to enable or disable definitions for 32-bit winapi. it is mostly used to prevent non-windows or portable source code from including windows headers:

//crtdefs.h
...
#if     !defined(_WIN32)
#error ERROR: Only Win32 target supported!
#endif

Open in new window


another application of the macro is to suppress gui specifics for example when including a windows header by a console application (without _WIN32 defined):

//commctrl.h
...
#ifdef _WIN32

#if _WIN32_WINNT >= 0x0600
#define HBITMAP_CALLBACK               ((HBITMAP)-1)       // only for SparseImageList
#endif

WINCOMMCTRLAPI BOOL        WINAPI ImageList_Replace(__in HIMAGELIST himl, __in int i, __in HBITMAP hbmImage, __in_opt HBITMAP hbmMask);

WINCOMMCTRLAPI int         WINAPI ImageList_AddMasked(__in HIMAGELIST himl, __in HBITMAP hbmImage, __in COLORREF crMask);
WINCOMMCTRLAPI BOOL        WINAPI ImageList_DrawEx(__in HIMAGELIST himl, __in int i, __in HDC hdcDst, __in int x, __in int y, __in int dx, __in int dy, __in COLORREF rgbBk, __in COLORREF rgbFg, __in UINT fStyle);
#if (_WIN32_IE >= 0x0300)
WINCOMMCTRLAPI BOOL        WINAPI ImageList_DrawIndirect(__in IMAGELISTDRAWPARAMS* pimldp);
#endif
....

Open in new window


and there are also a few places where the _WIN32 is used to distuingish between 32-bit Windows and 16-bit Windows:

//
// Make sure FAR is defined...
//
#ifndef FAR
#ifdef _WIN32
#define FAR
#else
#define FAR _far
#endif
#endif

Open in new window


Sara







headers the #else branches often contain code for 16-bit windows, mac os, os/2
0
 

Author Comment

by:LuckyLucks
ID: 40599445
so just to clarify: the WIN32 preprocessor primarily distinguishes between windows OS and non-windows. It has nothing to  do with 32 or 64 bit windows OS.
0
 
LVL 33

Expert Comment

by:sarabande
ID: 40600074
so just to clarify: the WIN32 preprocessor primarily distinguishes between windows OS
no, most cases where _WIN32 was used is to distinguish between WIN32 projects and non-WIN32 projects, what means between projects using the win32 api or not. to the latter group belong all console programs which do not use winapi.

It has nothing to  do with 32 or 64 bit windows OS.
yes. 64-bit windows is a product of the last decade. the WIN32 macros are more than 40 years old and their main purpose was to distuingish between 16-bit windows and 32-bit windows and to suppress definitions only needed for winapi.

Sara
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now