VS 2005 Symbol mapping does not work in case of #ifdef - visual-studio

I am using VS 2005 as my IDE. Most of my source code uses pre-processor #ifdef. All the macro definitions that control #ifdef are present in a header file. Visual studio shows the code under #ifdef grey'ed out. Although the header file where the macros are defined is included in the source file. This is annoying since visual studio also will not create symbol mapping for the code it does not see. So in order to look for definition of a symbol I need to manually go and check it. I had added the header file where the macro definitions are present to the project. Also my include directories contain location of this file. Can someone tell my why would VS not recognize the macro definitions?
E.g.
File source.c
#include "defines.h"
#ifdef MY_DEFINE
int my_global = 0;
void foo(void)
{
printf("I am here");
}
#endif
File defines.h
#define MY_DEFINE
VS will show all the code under #ifdef as grey. If I want to check definition of my_global from other file I can not.

Related

How can I force IntelliSense to use ClInclude directories?

I just set up a new project from this repository in Visual Studio Community 2015. Looking at the Solution Explorer, every single header file from this repository is included in the project.
However, opening a file (for example, atomic.h), will lead to most include directives being underlined in red with a mouseover-text cannot open source file "...". Continuing with the example file:
#ifndef ATOMIC_H
#define ATOMIC_H
#include "quantum.h" //underlined
#include <stddef.h> //not underlined
Yet the file is most certainly included in the project. It can be seen in the "Header Files" filter in the Solution Explorer. And it is included in the .vcxproj file:
<ItemGroup>
[...]
<ClInclude Include="quantum\quantum.h" />
[...]
</ItemGroup>
According to this answer, the inclusion of a file using the ClInclude tag should be enough to let IntelliSense find it, but it somehow doesn't seem to.
I can fix this by including every single folder and sub-folder separately in the VC++ Include Directories as mentioned here but that would take me hours. I also changed the double quotes to angled brackets, but that didn't help and I don't want to do that on a repo that I'm going to commit to either when it's working for everybody else.
Is there any way I can point IntelliSense to all the files that are obviously included in the project?
There's no need to build with MSVC, I only want IntelliSense to work properly.
I downloaded the example that you provided and got the same result like yours, from the .vcxproj file, the ‘ClInclude’ child element is under ‘ItemGroup’ element. This child element specifies the name of the header file for the C/C++ source file, we can know it from this, not means it will be auto complied.
We still need to add those parent folders of each #include "xxx.h" into the Node ‘AdditionalIncludeDirectories’ like you found. When you added it, then build and check the .vcxproj file, the addition include directory information should display like the following:
It will be a huge job to add those required folders into the Node ‘AdditionalIncludeDirectories’, you need to search the ‘xxx.h’ and find the record under ‘ClInclude’, copy the parent folder of this file and add into the node ‘AdditionalIncludeDirectories’ like the above, then reload the project and the intellisense works fine.

Visual Studio 2010 insert copy of resource with condition disappears after save

In Visual Studio 2010 I am trying to make a copy of a dialog template resource with a condition in order to have two different versions of the dialog in two different build configurations.
I have a header file that the .rc file includes which contains this:
#ifdef BUILD_CONFIG1
#define RES_DEFINE_1
#else
#define RES_DEFINE_2
#endif
So, I go to the Resource View in Visual Studio, right-click on the dialog template and choose "Insert copy..." The Insert Resource Copy dialog pops up and I set the condition: RES_DEFINE_2 and click OK.
At this point, everything looks good. I see both the original dialog and the copy with the condition in brackets [RES_DEFINE_2]. I save everything and I'm good to go.
Here is where the problem seems to be. Our version control system is ancient, and based on locking single files. In previous versions of Visual Studio, we've only archived the *.rc files, and made sure that resources were up-to-date by deleting the *.aps files that the resource editor creates. Whenever we needed to edit a resource, Visual Studio would simply regenerate the *.aps file from the *.rc file
But, when I delete the *.aps file in VC2010, and then reload the resource in the editor I'm now missing the conditional resource that I just added. Instead, I see only the original IDD_DIALOGNAME entry. I look in the *.rc file and see what I'm supposed to:
Original dialog:
#if defined(APSTUDIO_INVOKED) || !defined(RES_DEFINE_2)
IDD_DIALOGNAME DIALOGEX 0, 0, 301, 190
...
Copied dialog:
#if defined(APSTUDIO_INVOKED) || defined(RES_DEFINE_2)
#if defined(APSTUDIO_INVOKED)
IDD_DIALOGNAME$(RES_DEFINE_2) DIALOGEX 0, 0, 301, 190
#else
IDD_DIALOGNAME DIALOGEX 0, 0, 301, 190
#endif
...
If I go through adding another copy, I get another template in the resource with no #if at all:
IDD_DIALOGNAME$() DIALOGEX 0, 0, 301, 190
...
Is the *.aps file no longer completely generated from the .rc file? Has anybody else run into this and have a workaround, or will I be forced to start storing the *.aps files in our version control system?
Update: Yesterday, I could get this bad behavior at will. This morning I showed my boss and he duplicated it. Now, everything seems to just magically work on both my machine and the machine we originally discovered this on. Haven't heard yet if my boss can still get it to happen.
Now nobody can duplicate this issue. We weren't able to find any difference in the steps we took. Lacking any steps to duplicate this, I'm answering it to remove it from the list of outstanding questions.

VS 2008 resource type error while changing language

While changing the language of the resource elements in my visual studio project from english to azerbaijan I am getting this error:
error RC2144 : PRIMARY LANGUAGE ID not a number
and that line is :
LANGUAGE LANG_AZERI_CYRILLIC, SUBLANG_AZERI_CYRILLIC
What's happening here?
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#include <windows.h>
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#ifndef APSTUDIO_INVOKED
#include "targetver.h"
#endif
#include "winres.h"
The error is because the resource designer using constant (language ID) defined in winres.h, but the winres.h is not included in the resource file.
Add this line to resource.rc (view code as text, not from dialog editor), this will fix the problem:
#define APSTUDIO_READONLY_SYMBOLS
#include <winres.h>
#undef APSTUDIO_READONLY_SYMBOLS
P.S: you need also to define APSTUDIO_READONLY_SYMBOLS to keep include winres.h because Visual Studio will always keep removing #include
With Visual Studio 2015 These lines always been overwritten when editing resources.
To add this includes with Visual Studio 2015:
Go to "Resource View" Ctrl+Shift+E
Right click on the resource.rc file and select resourceincludes
Add to the write protected symbols:
#include "winres.h"
Simply add #include <windows.h> to your resources.rc file. Sometimes the line is not generated.
It's lame, I know.
The solution was to change the line LANGUAGE LANG_AZERI_CYRILLIC, SUBLANG_AZERI_CYRILLIC from the resource file to LANGUAGE LANG_AZERI, SUBLANG_AZERI_CYRILLIC as defined here.
It seems like visual studio generated that code erroneously.

How to differentiate multiple targets with Xcode 4.2

I've developed a lite version of an app. Now I want to create a paid version.
So I've duplicated the target, changed its name (so change plist and other stuff with that name) and now I have to differentiate in code. I'm using Xcode 4.2 and I see on the web that I have to create a preprocessor flag. My problem is that this flag in Xcode 4.2 is only in the project's build setting and not in the target's build setting.
I will need to be able to do something like this:
#ifdef paid
...
#else
...
#endif
Use preprocessor macros to do this.
Go to Target -> Build Setting and choose "All configurations" (this is very important).
Next find field "Preprocessor Macros".
In this field, add the flag in ex. PAID_VERSION. Now you can use this flag in code:
#ifdef PAID_VERSION
NSLog(#"Paid version");
#else
NSLog(#"Lite version");
#endif

Visual Studio 2005. RC File includes

I'm programming in C++ on Visual Studio 2005. My question deals with .rc files. You can manually place include directives like (#include "blah.h"), at the top of an .rc file. But that's bad news since the first time someone opens the .rc file in the resource editor, it gets overwritten. I know there is a place to make these defines so that they don't get trashed but I can't find it and googling hasn't helped. Anyone know?
Add your #include to the file in the normal way, but also add it to one the three "TEXTINCLUDE" sections in the file, like so:
2 TEXTINCLUDE
BEGIN
"#include ""windows.h""\r\n"
"#include ""blah.h\r\n"
"\0"
END
Note the following details:
Each line is contained in quotes
Use pairs of quotes, e.g., "" to place a quote character inline
End each line with \r\n
End the TEXTINCLUDE block with "\0"
Statements placed in the "1 TEXTINCLUDE" block will be written to the beginning of the .rc file when the file is re-written by the resource editor. Statements placed in the 2 and 3 blocks follow, so you can guarantee relative include file order by using the appropriately numbered block.
If your existing rc file does not already include TEXTINCLUDE blocks, use the new file wizard from the Solution Explorer pane to add a new rc file, then use that as a template.
You want to Include Resources at Compile Time (MSDN).
Within Visual Studio IDE, right-click on the .rc file (in the Resource View panel), and select "Resource includes" from the shortcut menu. When the dialog opens, use its "Compile-time directives" area to enter whatever you want to include in the .rc file. For example, if you want your 64-bit and 32-bit builds to use different icons, you could include the appropriate resource file for each build as follows:
#ifdef WIN64
#include "Icons64.rc"
#else
#include "Icons32.rc"
#endif
It's worth noting that these defines are not set in the resource compiler by default, so for your 64 bit build make sure you add /DWIN64 to the rc build.
All the gory details can be found in MFC Technote #35.
-Ron
I'm not completely sure why you're trying to do, but modifying the resource files manually probably isn't a good idea.
I believe general practice for VC++ for globally-accessible values is to define them in stdafx.h (at least that's how I've seen it done), or to create something like a "globals.h" header file and include that wherever you need it. It really depends on what you're trying to accomplish though.

Resources