40

When we add a 64bit configuration from a 32bit project that has already existed, Visual Studio copies the 32bit configurations by default. VS even copies _WIN32
All my 64bit projects define also _WIN32 now, despite they(64bit PEs) never can run on 32bit Windows. It is very uncomfortable to me.

I'd like to remove the _WIN32 if it doesn't have any problem. I'm not sure about that.
Is it okay if I remove the _WIN32 definition?

Piotr Dobrogost
  • 41,292
  • 40
  • 236
  • 366
Benjamin
  • 10,085
  • 19
  • 80
  • 130
  • Is it OK? Don't know. What is your objective? – Oded Jul 13 '11 at 13:11
  • You just want to know if it is OK to remove, but you are not providing enough detail about where the application is supposed to execute (will it be running on 32bit? yes? no?) What problem would removal solve? – Oded Jul 13 '11 at 13:17

4 Answers4

75

_WIN32 doesn't mean what you think it does. It means "I am using the Windows API". The 32 postfix was added back in the days of Windows NT 3.1 to make it distinct from the 16-bit API that was used in Windows version 3. This term has fallen out of favor because of the bitness problem. You can see this at stackoverflow.com, the [win32] tag takes you to [winapi].

Don't remove it, you are using the Windows API.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
55

The documentation for the predefined macros says:

_WIN32: Defined for applications for Win32 and Win64. Always defined.

_WIN64: Defined for applications for Win64.

So not only should _WIN32 always be defined, it does not cause any problem in 64-bit applications. Therefore, I'd suggest you don't remove it.

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
13

You should never define either of them.

The toolchain (compiler + system headers) will define them as appropriate.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • I think this is technically incorrect - the MSVC compiler always defines _WIN32, it does not define WIN32 unless it is told to by its input e.g. a /DWIN32 option. Many projects (tell the compiler to) define WIN32, but that is the project's decision, not the compiler's. – Spike0xff Dec 16 '19 at 21:53
  • 1
    @Spike0xff: Good point, not all the system macros are necessarily predefined in the compiler binary itself. Hopefully this edit made the answer more accurate. (on the other hand, the question and answer were about `_WIN32` not `WIN32`, and about `_WIN64` not `WIN64`) – Ben Voigt Dec 16 '19 at 22:08
  • good point about the OP! Great edit, I reversed my vote. (incidentally props on your profile statement ;-) – Spike0xff Dec 18 '19 at 00:27
5

_WIN32:Defined for applications for Win32 and Win64. Always defined.

_WIN64:Defined for applications for Win64.

More detail: Predefined Macros .

To put it simply, WIN32/_WIN32 is used to tell whether you are using Windows(For crossing system application), while _WIN64 is used to tell the compiling environment is x86 or x64.

If you want to know whether your application is running under Windows x64, you should use Windows API IsWow64Process .

Corey
  • 15,524
  • 2
  • 35
  • 68
Destiny
  • 466
  • 5
  • 8