visual studio 2010/2012 setting to undef _WIN32 and define __GNUC__ - visual-studio-2010

This would be a very weird question, but is it possible to undef _WIN32 and define __GNUC__, in visual studio 2010/2012 settings without touching any source codes?
I added _WIN32 in "C/C++ -> Preprocessor -> Undefine Preprocessor Definitions" (which is /U"_WIN32"), but looks like it is not honored by visual studio IDE.
The reason of doing this is to write linux/mac parts of code with the help of visual studio IDE and intellisense. Of course, this wouldn't compile, but as far as intellisense correctly parses and helps for __GNUC__, I'm ok. I just need autocomplete and other features.
Maybe someone wants to argue why I am using visual studio for linux? Well, all vcxproj/sln are already configured for windows, and I want to take advantage of it. So.. let's not discuss about other options, such as source insight, emacs tags, etc...

I ran in to this problem as well and was able to get around the issue by doing the following in a globally included header. One was already in play for me so I didn't have to deal with including the header everywhere.
#ifdef _WIN32
#undef _WIN32
#endif

The preprocessor macro _WIN32 is always define when using the microsoft compiler and it cannot be redefined/undefined (source: http://msdn.microsoft.com/en-us/library/b0084kay(v=vs.80).aspx)

Related

Visual studio, intellisense and custom compiler settings

Please excuse me if this question is inappropriate, I switched to windows together with my linux code which is based on c++11 so I have 2 options, to change the compiler or rewrite my code, I'm prety sure I won't rewrite all the code but replace MSVC "C" compiler with something better like clang++ or g++.
But I'm unsure whether this will broke intellisense of visual studio and what can I do about that?
I would like to have both functionlaities, c++11 and good code completion in visual studio.
can you recommend what actions/compilers(other stuff) to take before struggling with new compilers and code completion settings?
I'm also unsure whether all that will work anyway.. thanks.

How to get rid of warning squiggles for WPP TraceEvent macro?

When using WPP in Visual Studio (2012) each occurence of TraceEvents(...) has a wavy underline and the help text is e.g.
#define TraceEvents WPP_(CALL)
error: identifier WPP_Call_Foo_cppNNN not defined
Well, it is defined, in the .tmh header file created by the WPP preprocessor and the project compiles just fine. But Visual Studio doesn't scan and/or recognize this file.
Is there a practical way of getting rid of those squiggles?
For now I work around the problem by putting
#ifdef __INTELLISENSE__
#undef TraceEvents
#define TraceEvents(a,b,...)
#endif
in one of the header files that are included after the .tmh in all of the files anyway.
The define __INTELLISENSE__ is mentioned in http://blogs.msdn.com/b/vcblog/archive/2011/03/29/10146895.aspx
Edit for Visual Studio 2012:
It appears you've reached the analysis limit of the preprocessor in Visual Studio 2012's IntelliSense engine. If you replace the TraceEvents reference with WPP_Call_Foo_cppNNN, it actually resolves the identifier without problems (until you rebuild the solution and the tmh header changes).
The solution is to load the solution in Visual Studio 2013, and choose to not upgrade the compiler toolchain, thus preserving backwards compatibility with Visual Studio 2012.
Previous Answer for Visual Studio 2013:
This was tested in Visual Studio 2013, so it may not apply to Visual Studio 2012. I couldn't find a release of the WDK that supports Visual Studio 2012, so you'll need to let me know how to configure the environment if the following steps do not work.
After building your project (to ensure the .tmh files exist), execute the Project → Rescan Solution command.
I also recommend you associate the files with the C++ editor through the following steps:
Open Tools → Options... → Text Editor → File Extension
Associate extension tmh with editor Microsoft Visual C++
Switch off the Live Semantic Errors in Options->Text Editor->C/C++ -> Advanced ...

Visual studio C++ IntelliSense issue

I seem to be having two issues with my project after I converted from VS 2005 to VS 2010.
IntelliSense: command-line error: invalid macro definition:
_WIN32_WINNT>=0x0501
And I also cant seem to be able to do a "Call Hierarchy" on any of the methods or properties.
I would appreciate if someone can help me with these. Thanks
I just encountered the same issue - the same error message, the same non-functioning call hierarchy and badly-working Intellisense.
The problem was with the preprocessor flags in the project, the following were defined:
WIN32;_DEBUG;WINVER=0x501;_WIN32_WINNT 0x0501
Notice the lack of = after _WIN32_WINNT. Adding the = fixed all the issues.
P.S., this is a Console application that doesn't use any of the Windows header files, which is why the lack of the _WIN32_WINNT macro did not cause a more severe problem.
Decided to ignore the intellisense warnings. The call hierarchy wasn't working because I was in the release mode. Should be in debug mode.

Visual Studio Intellisense crashes due to macro file

In Visual Studio 2005, I have a .h file with preprocessor macros in it. They are apparently too complicated for Visual Studio's Intellisense because they make Visual Studio crash if they are present whereas it works fine if they are not. Does anyone know of a way to prevent Visual Studio parsing the file for Intellisense but still include it in the build. By the way, I have already tried the following:
Disabling Intellisense by renaming feacp.dll. Works, but impractical.
Visual Assist. Works, but $250.
Installing Visual Studio SP1 + the Intellisense hotfix (KB947315). Doesn't fix it (and ate 1GB of hard drive space).
The first thing to try is to install Visual Studio 2005 SP1. This fixes a lot of intellisense related issues which may help you out
http://msdn.microsoft.com/en-us/vstudio/bb265237.aspx
If that doesn't fix the problem try excluding the file from the project. This prevents it any any of it's contents from appearing in Visual Studio features (such as intellisense). If it's just a header file it shouldn't impact the build as the actual file won't be removed, it just won't be considered part of the project.
Ok, for the benefit of others, I'm going to solve this myself! I've been fiddling and the answer is as follows. If you have this problem, and you delete your ncb file to force Intellisense to update, you can prove to yourself that this works.
#ifdef out the offending code in your .h file as follows:
#ifdef SOMETHING_UNIQUE
<the offending code>
#endif
in the file that actually uses the macros (the cpp file that #includes the .h file):
#define SOMETHING_UNIQUE
Intellisense will now ignore the code in the .h file that causes it to crash (it will be greyed out in the editor), but it still gets compiled.

Where can I find visual studio macro examples?

When I look up anything about macros for Visual studio 2005, everyone is referencing the samples that ship with it. However, Visual studio was installed for me (IT department) and I do not have these sample macros.
Is there another place I can find(or download) them?
Note that you can also create your own using the macro recorder (Ctrl+Shift+R). After you record some actions, stop recording (ctrl+shift+R again), you can view the macro source using the Macros IDE (Tools | Macros | Macros IDE).
In VC 6 they used to be in a normal file from what I remember, but I'm not sure where they are kept in VS2005 and VS2008. I can't imagine that there is an install option to not include them.
Did you look in the Macro IDE or the Macro Explorer?
http://msdn.microsoft.com/en-us/library/s2shw615(VS.80).aspx
The Macros IDE includes some sample macros for your study and use. They are located in a node called Samples and are available in either the Macro Explorer or the Macros IDE. The following is a list of the macro samples and a description of what they do.
Try here for examples and tutorials
Code Project
Line Counter Add-in

Resources