How does Windows know what program to open a file with? - c++

I just noticed that when I view the .sln files on my computer, that some have a v7.1 icon, some have a v9 icon, and some have a v10 icon (depending on what version of Visual Studio created them). It appears that Windows distinguishing which files get which icons, possibly via some sort of "MIME type" for files apart from the extension.
Could I use that functionality to detect which filetype a user selects from the default MFC SaveAs dialog if two filetypes share an extension?

In case of Visual Studio, the .sln files are associated with Microsoft Visual Studio Version Selector, which, on my machine, is installed under "C:\Program Files\Common Files\microsoft shared\MSEnv\VSLauncher.exe"
This executable must parse the solution file to determine the version, and then present the right icon to explorer.
In the general case, file associations for a given file type are present in the registry, under HKEY_CLASSES_ROOT.
But in your case, I think you're just going to have to read the file contents to determine which one it is. Hopefully there's something easily distinguishable between the two.

Related

How to specify an application icon for C++ Visual Studio 2019?

I've seen this documentation for C#/Visual Basic application icons, but there is nothing I can find for how to do this with the C++ version.
This StackOverflow question is for Visual Studio 2008, not 2019. This one is also obsolete, as it works for Visual Studio 2017 but not Visual Studio 2019.
After some fiddling I figured it out. This answer for VS2017 was basically correct, but it didn't fully explain what you have to do to get it to work and the documentation it links to was vague enough to confuse me, so I'll post this answer as the VS2019 version with full and complete easy-to-follow instructions.
Navigate to your Solution Explorer tab.
Find the Resource Files folder in your project, probably near your Header Files and Source Files folders.
Right-click on the Resource Files folder and select "Add > Resource."
In the "Add Resource" window that pops up, select Icon and select Import.
Import either a bitmap file or your custom .ico file.
Now a Resource File (.rc) is created which contains your application Icon, in the form of an Icon node. Click on that .rc file to open the Resource View tab.
You'll see that there's a folder called Icon. It should contain your new icon.
If it contains a default Icon file, probably named IDI_ICON1, you'll have to edit that node to make it the icon you want to use. I don't know why it does that.

Is there a method to automatically attach a .natvis to debug session started using -DebugExe?

I am working with a solution that includes a .natvis in its tree. The workflow requires that I often start debug sessions of various solution's executables using devenv.exe's /DebugExe switch. But when started this way, the .natvis file isn't used by debugger.
I have tried to use /Command switch with Add Existing Item command, but it looks like since the debugged .exe isn't a proper solution or project, it's impossible to add anything to it (at least I have failed).
So the question is: is there a method to use the .natvis placed in an arbitrary path (not in user's profile where VisualStudio would automatically use it) in /DebugExe sessions?
You could use /NATVIS:filename to add your .native file to the .pdb file. It will embed the debugger visualizations defined in the Natvis file filename into the PDB file generated by LINK.
In addition, you could refer to the Deploying .natvis files part in the link Jack provided. We also could add the .natvis file to user directory or to a system directory. The order in which .natvis files are evaluated is as follows:
natvis files embedded in a .pdb you are debugging (unless a file of the same name exists in a loaded project)
natvis files that are part of a loaded C++ projects or a top-level solution item. This includes all loaded C++ projects, including class libraries, but it does not include projects of other languages (e.g. you can’t load a .natvis file from a C# project). For executable projects, you should use the solution items to host any .natvis files that are not already present in a .pdb, since there is no C++ project available.
The user-specific natvis directory (%USERPROFILE%\My Documents\Visual Studio 2015\Visualizers
The system-wide Natvis directory (%VSINSTALLDIR%\Common7\Packages\Debugger\Visualizers). This is where .natvis files that are installed with Visual Studio are copied. You can add other files to this directory as well if you have administrator permissions.

Visual Studio & C++: Use filters as directories

I Use Visual Studio 2012 Professional and C++. When creating so called 'filters' and adding source files to them, the files in the solution explorer are divided into sub directories, while on the file system they are all in the same directory (the project directory)
Question: I want to add a file to a filter while at the same time adding it to the corresponding directory on the file system. How can this be accomplished other than manually moving files around?
One alternative would be to switch to "Show All Files" in Solution Explorer top menu.
This way you can move and manage files in folders.
Filters will not get used though.
The "Show All Files" solution did not work for me because in my case the source files were not located under the directory containing the project file.
I finally ended up with writing a VS extension which allows you to organize either the filter structure inside the project or the file structure on the disk automatically by invoking a command through the context menu. I thought some of you might be interested in that extension too:
https://github.com/reloZid/vc-fileutils
I know only this workaround: you create first the folder structure in windows explorer and then drag / drop the files / folder from windows explorer into the solution explorer of Visual Studio.
It will add them all as a "filter" to Visual Studio!

Move files in Visual Studio and AnkhSVN simultaneously

I'm reorganizing my project in visual studio. I have some .cpp/.h files which I want to move into a subdirectory physically. A would like to have the following acts simultaneously:
File moving on file system
SVN working copy database updating (with keeping history)
Visual Studio project file(s) updating
Extra benefits would be nice, like:
Updating of #include directives referring to the file.
Are there any solutions? Best workarounds?
This is the proverbial chicken-and-egg dilemma for software developers:
Do you move/rename your files in Visual Studio first then go back to Windows Explorer and correct all the adds/deletes that should really be renames/moves?
Or do you rename/move your files in Windows Explorer then go clean up all the introduced compilation errors in Visual Studio?
You already have the solution at hand! Without AnkhSVN if you do your file operations in Visual Studio you already get two of your requirements: updating your VS project and file system synchronization. With AnkhSVN installed, though, you also get your 3rd requirement: it makes the necessary SVN synchronizations as well. All you have left to do is a commit.
I found the following description from a cached page in a Google search:
In Windows Explorer, right-click and drag the file from its old
location to its new location, then select "SVN move versioned item"
from the context menu. This will not only move the actual file itself,
but it will also make sure that all the file history stays with it
after you check in your changes. Back in Visual Studio, use the
Solution Explorer in VS2010 to "exclude from project" the
(now-missing) copy of the file in its old location, and then "include
in project" the file in its new location. You may need to refresh the
view in solution explorer and/or make sure you are viewing all the
files by clicking the "Show all Files" icon at the top (next to the
refresh icon) in order to see these files.
After you update the namespace to reflect the new location, I
recommend using a global find and replace before you try to compile to
save yourself a lot of trouble.
Hope this helps.

Visual Studio unmanaged C++ smart file explorer

I use Visual Studio to develop unmanaged C++ apps for a living.
Is there an add-on tool (price isnt the issue) that is smart enough to detect folders that I create within my solution folder and add them to the include path (/I)? It would automatically do this for win32, or x64 platform settings, or debug, and release, etc.
It should also be smart enough to remove the include paths if folder is deleted
Arent you frustrated sometimes when you double click a file under solution explorer and Visual Studio says it cant find the file because somebody moved or renamed it? ---> Is there a tool that would periodically scan the files in Solution Explorer and automatically removes or prompts the user to let them know those files are no longer valid?
Like John Lakos once said, I too would pay for an add-on that can automatically add #include into my code by just parsing my project's .h/.cpp files.
When is Visual Studio going to have an Eclipse-like solution explorer that allows user to directly manipuate the files/folders structure directly from within Visual Studio?
You can manipulate files/folders from the IDE! Just click the "show all files" button in the solution explorer (2nd from left, at the top). I just recently found that out.