Specific difference between _WIN64 and TARGET_X64 macros in Visual Studio - c++

Most of the time _WIN64 macro was working well with Microsoft Visual Studio 2008 but TARGET_X64 not working well.Please explain these two macros with specific example.

The Visual C++ compiler predefines _WIN64 when compiling for a 64-bit target. To test for x64/amd64 specifically, test for _M_X64 instead. Consult the documentation for other macros that are predefined by the compiler.
TARGET_X64 is defined by neither the Windows SDK nor the Visual C++ libraries or toolchain. It must be defined somewhere else in your project or one of its dependencies.

Related

Visual C++ application won't run on windows 7

I am using Visual Studio Community 2015 and I wrote some simple Win32 demo application which should download file from internet and execute two HTTP GET requests.
I am using functions like InternetOpenA, InternetConnectA, HttpOpenRequestA, URLDownloadToFile, etc.
Only thing that I have changed in settings is Platform Toolset to Visual Studio 2013 (v120) and my targetver.h file looks like this:
#pragma once
// Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
#include <WinSDKVer.h>
#define WINVER 0x0600
#define _WIN32_WINNT 0x0600
#include <SDKDDKVer.h>
However, it runs on my Windows 10 computer, but it does not run on windows 7. It says: Missing MSVCR120.dll file. I can install appropriate C++ Redistributables but that is not solution that I need.
Is there any other options I need to include when I compile so I can avoid this error?
To avoid your application needing a separate runtime DLL, in the project settings, look under:
C/C++ > Code Generation > Runtime Library
and choose multi-threaded, rather than multi-threaded DLL.
You do not need to change the platform toolset.
In my project, that I compile with VS 2017 and want to run all the way down to Vista, I do the same as you, but without the first #include <WinSDKVer.h>. I just set the _WIN32_WINNT macro to 0x0600 and so far it's working fine.
I target the Windows 8.1 SDK, and use MFC, if that helps.
I've used dependency walker in the past to diagnose dll dependencies. Hopefully it's something silly like the 32-bit or 64-bit runtimes being missing.
As keith recommended in his answer, you can also try static linking the vc runtime (/MT[d] under C++/Code generation/Runtime Library) so that it doesn't need to load the runtime as a dll. Note that this is not the recommended option, since the VC runtime cannot be patched by Windows Update if it's burned into your executible.

Visual Studio _MSC_VER versus Platform Toolset

I have a VS 2010 C++/CLI project that I imported into VS 2015. Because it links against some VS 2010 C++ libraries that I don't control, I need it to be compiled with the VS 2010 compiler. When I imported the project to VS 2015, I told VS not to upgrade the project (don't remember the exact options, but the project now says "Project Name (Visual Studio 2010)" in Solution Explorer). In the project properties, the Platform Toolset is listed as "Visual Studio 2010 (v100)":
One of the libraries I'm using has a header with some ifdefs that show an error if _MSC_VER isn't one of the supported versions (Visual C++ 6.0-10.0). That error is being generated for this project, and I've determined that the _MSC_VER showing up during build in Intellisense is 1900 (the default for VS 2015).
How do I get the project to build with the 2010 version of the C++ compiler (_MSC_VER 1600)? Isn't that what the Platform Toolset option is supposed to control?
I misunderstood what was going on in Visual Studio. The build was actually working fine; the error being generated was coming from Intellisense. There's a known bug in Visual Studio where Intellisense doesn't properly reflect the _MSC_VER specified by the project's selected Platform Toolset. I'll leave the question up in case anyone else runs into this problem.

C++ Visual Studios 2015: #ifdef WIN32 not executing properly

I am working on a large inherited C++ project and am trying to build it for the first time in VS 2015.I have all the build files, but my build is failing in visual studios because the conditional
#ifdef WIN32
.....
#else error
I am trying to run on windows, but the program always is falling back to the else statements logic.
I have everything possible installed for C++ in visual studios. Any help is greatly appreciated.
VS 2015 defines _WIN32, not WIN32. See this list of predefined macros.

Why isn't __clang__ defined when using LLVM+Clang in Visual Studio?

I installed LLVM for Windows, which includes Clang and a few other tools. It integrates with Visual Studio, and even lets me choose a "Platform Toolset" in the project properties. However, when I choose any of the toolsets that came with LLVM, __clang__ isn't defined, and _MSC_VER is defined instead. How do I make __clang__ defined when using LLVM and Clang in Visual Studio?
My Visual Studio version is the 2015 Preview (however I have also tested on 2013 with no success either), and my LLVM version is based off of SVN release 225473. I've tried LLVM-vs2012, LLVM-vs2013, and LLVM-vs2014 as the Platform Toolset without success.
Under Project Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions, add __clang__. Yes, this is just a workaround.

Which version of the Dinkumware STL Lib ships with Visual Studio 2012?

In earlier versions of Visual Studio, there was a predefinied macro "_CPPLIB_VER" which reported the version of the Dinkumware STL Library shipped with this version of VS. As of 2012, I am unable to find or use this macro - it is undefinied and I am unable to find any information on this matter online.
Is the Dinkumware STL Lib no longer used in VS2012? Was the macro renamed?
Windows 7 x64
Microsoft Visual Studio 2012 Professional
Usually the definition of _CPPLIB_VER can be found in a header file named yvals.h somewhere under your VS installation folder. For Visual Studio 2010 it's in VC\include.
Be careful because _CPPLIB_VER is no longer an official predefined macro since Visual Studio 2008.
The "Change History" section of Predefined Macros (Visual Studio 2008) on MSDN says:
Added Visual Studio 2008 values for _ATL_VER, _MSC_VER, _MFC_VER; removed _CPPLIB_VER; updated __COUNTER__, _DEBUG, _DLL, _MT, __FUNCDNAME__, __FUNCSIG__, __FUNCTION__, __FILE__. Cleaned up topic.
And the macro was one of the "Microsoft-Specific Predefined Macros" for VS 2005. See Predefined Macros (Visual Studio 2005):
_CPPLIB_VER
Defined if you include any of the C++ Standard Library headers; reports which version of the Dinkumware header files are present.