Solved

Preprocessor definitions

Posted on 2015-02-08
4
106 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 32

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 32

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

744 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

12 Experts available now in Live!

Get 1:1 Help Now