Cannot "Go To Definition" in Visual C++ 2013 - c++

In Visual C++ 2013 Professional, when I right-click CWinApp::Run(), an MFC function, in the afxwin.h header file and choose "Go To Definition" in the context menu, nothing comes up. The definition is also unavailable on this function's MSDN article. How can I fix the problem and find the definition? What would cause definitions to be unavailable?

You can't go to a definition of a function that exists in the MFC, you don't have access to the debugging information. Generally, you're only going to be able to access the definition of functions you have the source for. You can access the declarations, that's what you see in the header file.
As far as some problem you have, I'd lean toward your own code having a problem, not something in the MFC.

You can put a break point on any MFC function then debug it, and step in to the function (F11 key or "Step in" command). This will take you directly to source code, most of the time.
In this case, you may be redirected to this file for VC 2013:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\src\mfc\appcore.cpp

What Error is shown in the console?
All i can say to help is that you are suposed to call that function in a while loop, like this:
while(CWinApp::Run()){
//application code goes here...
}

Related

Visual Studio resource change

when we have resources in our project, Visual Studio creates two files: "resources.rc" and "resources.h". Now, every change in rc file (in visual editor), changes header file also.
Sometimes I need to add something manually to resource.h, but after any change in visual editor, my header changes may be even deleted.
I've noticed that VS uses some kind of comments that steers its behaviour. So maybe there is a way to say to VS: "Hey, don't touch this part of file" ?

Visual Studio warning about copies of files with different contents

When I go to debug my C++ project in Visual Studio, up pops a little warning dialogue box that tells me:
A copy of datum.h was found in
c:/users/brad/desktop/source/binary/datum.h, but the current
source code is different from the version built into
c:/users/brad/desktop/source/binary/datum.h.
I'm having trouble understanding what this is even trying to tell me, let alone how to fix it. At first I thought it might be complaining that I'd accidentally duplicated a file in the directory, which I checked, and found nothing of the sort, which leaves me pretty stumped. I also tried excluding the file from the solution and adding it again, which didn't fix the problem either.
The warning doesn't appear to actually hinder the development of my project, but I suppose warnings exist for a reason, so if anyone knows what's gone wrong, any advice would be greatly appreciated. To my knowledge, I didn't change anything to cause the message to appear, it just popped up one time I went to debug the solution and has kept on appearing ever since.
Also, more copies of the same warning have started popping up, pertaining to other header files in my solution (I haven't recieved any about .cpp files yet, but it could be a coincidence, because it's only been going on for about 20 minutes).
Try removing breakpoints from the file in question.
This worked for me when it occurred with Visual Studio 2013 for a header file in debug build.
Source: Release mode file sync issue - current source code different from the version built
Additional notes: Clean / Rebuild also works, but that is painful for regularly changing code. Enabling the break point after starting debugger merely delays the message.
I solved it:
Close the window of the .h file in Visual Studio if it's open.
Close Visual Studio.
CUT the .h file from its normal location and paste it into a temporary folder that VS doesn't know about.
Restart VS and compile. It'll complain about the missing .h file. Good -- Make the bastard beg for it!
Paste the .h file back into its original location.
Compile. VS will gratefully accept the missing file. (Damn I hate Microsoft!)
This occurs if you rename an implementation file (*.c, *.cpp, etc.) to a header file.
This is because the Item Type still remains as C/C++ Source File, making it get compiled as a separate translation unit rather than as an actual header, preventing Visual Studio from recognizing its inclusion as a header elsewhere.
It took me quite a while to figure this out.
To fix this:
Right-click your header file in Solution Explorer and select Properties.
Select All Configurations, All Platforms.
Under General, change Item Type to C/C++ Header.
Press OK.
Force-recompile any file that #includes your header (or just Rebuild the solution).
The problem is that the debugger thinks that the checksum of the source file is different from what the compiler calculated and put in there. The debugger will then refuse to apply breakpoints in the files that mis-match, to prevent you from seeing data it can't guarantee is correct.
I have had this keep happening even after a clean rebuild. This is with VS 2015. My guess is perhaps the debugger and the compiler disagree on how to hash newlines or something like that? The fix is to turn off "require source files to exactly match the original version" in Debug -> Options -> Debugging -> General
Could you by any chance be debugging another executable (not the one actually built?). This is a common issue in scenarios where Visual Studio builds the binaries in one directory but then they are copied over to some other directory for debugging. I'd suggest you compare the target path under the debugging settings and the output directory under the general settings in Visual Studio.
This would explain the issue, since you are actually debugging some older version of the binary (not the one built currently) and thus the warning, since Visual Studio can't find the version of the source files for that version of the binary.
The reason may be circular header dependencies. datum.h may includes another_header.h (directly or indirectly), which includes datum.h.
I see the real reason of this question is not answered. So for someone still looking, here it goes...
The most common reason of this problem is that the source files used to build the existing obj files are different than the existing ones. In other words the
particular project did not build after new modifications to source. The solution to this problem is to rebuild the project after modifying.
This happened to me in situation where I had modified my static library projects files and then without building that project I started my application project which was using this static library project.
this worked for me:
close VS
delete *.vcxproj.filters file
restart VS
problem should be gone.
this worked for me:
clean project
debug/delete all breakpoints :)
This worked for me (as of March 2019):
Click the 'Build' drop-down menu in the top left of your Visual Studio window
Select 'Rebuild Solution'
I've changed the file name and it works now.
Just encountered this. In my case, one of my .h files contained implementation (a class with static methods), which was #included by one of my .cpp files, but the Project Settings were also telling Visual Studio to compile the .h file.
I manually edited both the .vcxproj and .vcxproj.filters project files, moving the .h file from the <ClCompile> ItemGroup to the <ClInclude> ItemGroup.
This did the trick for me; I never saw the "A copy of...is different from..." pop-up again.(Note that this was after I had thoroughly failed in attempts to get <DependentUpon> to work.)
My solutiion:
Build -> Configuration manager
Switch to another configuration (any, example Releas or Debug)
Switch to previous configuration
It is possible to have multiple projects, each with their own entry point within a solution. Make sure that the correct project is being run.
The source code is different message can appear in a project A's source when you are running project B. In this case, the message can mean This breakpoint won't be hit because you're running a project that doesn't include it

How to identify C++ file linkage in Visual Studio?

I'm going through an old C++ solution in Visual Studio, and referencing certain sections for a new project. One file has this declaration:
vector <cDevice*> localdevices;
Visual Studio happily shows me where the "vector" type is defined, but I want to know exactly how the solution references that file. According to the "Find in Files" tool, there is no other use of the text "vector" in the solution, and the file isn't among the "Additional includes" either. How does the project "know" what a vector is?
Edit: The project does not build, and I don't feel like fixing that, since I'm ultimately trying to rewrite the code anyway.

Does Visual Studio support C++ code indexing?

Does Visual Studio have a source code indexing feature for C++? That is, it statically parses your project, storing symbols in an index, such that you can easily and quickly jump to a definition of a symbol or see uses of it (i.e. call hierarchy)?
From what I can tell, in Visual Studio 2010, it has "Go to Definition" and "View Call Hierarchy" functions (if you right-click a symbol), but it takes a long time (a minute on my project) to find the info and do the action. It seems to be doing a crude text search in some cases.
I'm used to using Eclipse, which has an indexer, so those actions are almost instantaneous (after the indexing has completed).
Yes, Visual Studio Intellisense does just this. If your "go to definition" is taking a long time, it indicates that the project is not set up properly inside Visual Studio. You should be able to hover the mouse over a symbol (function name, variable name, etc.) and Intellisense should pop up instantly.
One cause of slow or incorrect Intellisense is creating a new project from a folder structure. If you have a bunch of .cpp and .h files in a complicated folder hierarchy, sometimes the project does not get created in a way that Intellisense can easily do symbol indexing. Also, if your project uses a lot of third party libraries, you need to make sure the header files are included in your project or else Intellisense will not be able to do anything with those symbols.

Control Click to get definition in IDE does not work

I am using C++Builder, I know that to go to a definition of a variable or class you must press control and click on the method name, or any identifier where you want to go to a definition.
However, as most of you would notice this does not work all the time.
Does anyone have any trick on doing this?
"Go to declaration" usually succeeds when invoked from a source file, but fails when invoked from a header. It's easy to understand why if you know how it works: When you perform Ctrl+Click on an identifier, the compiler kicks in, running in a special "Kibitz" mode, and basically compiles your source code up to the position of the caret. For a .cpp file, this is easy - those can usually be compiled standalone. A header file, however, often depends on other headers but doesn't include them explicitly - i.e. doing a standalone compilation on "sysmac.h" will fail with an error because that header expects "System.hpp" to be included beforehand. This is one of the reasons why Code Completion and Code Browsing often fail when invoked in header files.
If you run the Precompiled-Header Wizard.. under the Tools menu in Codegear 2009, it may improve the performance of the Go to Definition function.
I actually used the Visual Studio Emulator for keys and because of that I can now right click a popup menu and go to definition.
Another benefit of enumlating the Visual Studio keyboard setup is the multiple line tab and alt-Tab now works. Sadly no more shortcut to compile (F6 for RAD Studio 2007 default keyboard setup).