How to use Resource.RC file in Visual Studio - c++

For context, I have been trying to include 2 PNG files with my C++ code, but I have not been able to figure out how to do so in Visual Studio 2019. I have searched through the docs and have not found anything helpful. How could I accomplish the three items listed below?
Correctly include files in a Resource.RC file (and correctly create a Resource.RC file)
Access these files in a filesystem-independent manner in C++ (no absolute paths)
Include these files when distributing an executable
My solution is laid out in the default manner: a References folder, External Dependencies folder, Header Files folder, Resource Files folder, and a Source Files folder.

add .rc file refer tomicrosoft document, you can use or load this rc resource refer to this link, windows api findresource and loadresource can use this rc file resource by define resouce id

Related

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.

Import idl files into Visual Studio (C++)?

I am trying to build an application using the BlackMagic DeckLink SDK. They have a folder in their package which has a bunch of .idl files. The manual says I have to inlcude the idl file. Whats the best way to include this file so I can access its code?
I've tried putting them in the source files folder next to the main class but I still get errors that they can't be accessed.
IDL file it self can not be accessed directly.
First you have to generate associated ".c" and ".h" files.
Then you can consume those files by including in your project.
This process of generating "c" and "h" files, you can make it as a part of your build process.
Add the IDL file to your C++ project in visual studio.
Go to properties, you will see "custom build tool".
You can build the idl from there and create the files (.c,.h) in a known location and include them.
The below link has a screenshots explanation, regarding commands to use and how to specify custom build.
https://community.rti.com/howto/how-add-idl-file-visual-studio-project
So for your project, add all your IDL files to C++ project (say IDL folder), and provide a custom build to every IDL file (as explained in above link) , and create the output "c" and "h" files in a directory (say "generated"). Then include the headers and "c" files as required, from the "generated" folder into your project.

Why does Visual Studio generate these additional files?

In the output directory where Visual Studio places the compiled executable, there are three additional files of the types *.exp, *.lib, .pdb. I do not need those files and I would like to prevent the compiler from creating them.
This is how my build output directory looks like. I only need the *.exe file.
What are these additional files for? How can I disable that they are generated? If they are needed for the build process, is there a way to automatically remove them after the executable is created?
I am using Visual Studio 2012. If you need additional details, please comment.
EXP and LIB files But I don't want that .lib or .exp file for my COM library! . You could probably set the location of these files in the "Intermediate Output" setting and not have them in your release folder
I'm assuming you are looking to have only the dll and exe files in your final release directory and the *.exp, *.lib, .pdb files left in your intermediate directory as to not clutter the directory you are working in.
Visual Studio 2017
Open properties (Right click on the project in the solution explorer):
change settings as shown:
Import Library will define where the .lib and .exp files are created.
Generate Program Database File defines where the .pdb file is created.
Debug information format -- None will prevent pdb file from being created. Select this option for Release builds.
There some functions inside declared with as __declspec(dllexport).
It means that they are exported and linker thinks that there is a need to link with this dynamic library (no matter it is exe or dll - in general the structure is the same) and creates *.lib and *.exp file

Unable to include header file in C++ console application project

I have been trying linking of a .lib file and also including a header file in my C++ console application project. I copied the C++ header file from one of my other projects, and pasted it under Header Files folder in console application project. Here's the screenshot to see: http://i.imgur.com/JFFIn.png
However, when I try to include the header in my code as #include..., I do not get an intellisense with my header file's name. (I only see targetver.h, stdafx.h and Debug folder)
I tried to point Add additional include directories in my C++ console application project properties to the Project folder itself, but that doesn't seem to help and the file still doesn't show up.
If I write the name of the header file as #include "DllTest.h", I get an error saying: Cannot open include file: 'DLLTest.h': No such file or directory c:\users\ht\documents\visual studio 2010\projects\dlltest\dlltestconsole\dlltestconsole.cpp
How is the header file included in here, so that it starts appearing? If I add a new item > Header File, name it to DLLTest.h and copy paste the header files content here, it just shows up normally. How will the header file which is copied - pasted into Header Files folder show up in the code?
In C++ projects, the things that look like folders in the Solution Explorer aren't actually folders, they are filters. They are UI-only entities that can be used to organize project items in the IDE. They do not in any way reflect the structure or location of items on disk, though. You can add a file from any location on disk to any filter in the solution.
The compiler knows nothing of these filters; it only knows about files as they exist on disk.
In your case, the files are not located in your project folder. You'll either need to:
copy your files into your project folder, then add them to the project from there (right-click on the solution then Add Existing Item), or
add the files from where they are, then add their location to the "Additional Include Directories" property in the project properties.
I do not know of any way to have the IDE automatically move files to the project directory when you copy and paste them into the project. The C++ project system is fundamentally different from the project system used for C# and VB.

CMake and Visual Studio resource files

I am converting a C++ project created using Visual Studio 2005 to CMake and have stumbled upon a bit of a problem with resource files that are included in the project.
The project includes a .rc file, a bunch of .ico files and a .rc2 file.
The regular .rc file works fine in the generated project and uses the resource compiler. The .ico and .rc2 files however are causing problems when they are just being included, because in the generated project Visual Studio attempts to compile them using the C/C++ compiler.
I assume that these files are included by the .rc file, so it would probably work to just not include them in the CMakeLists.txt file, but since it is obviously possible to list them in the project (they are visible in the original project) I would like to do so, so that the user of the generated project can see that these files are being used.
What is the correct way to handle these extra VS resource files in CMake?
Try to set_source_files_properties(your.ico your.rc2 PROPERTIES LANGUAGE RC).
By default it shouldn't do anything with those files. The source file property LANGUAGE should be empty and thus the action for the file should be checked by the file type. Which shouldn't be anything since it's not something it should compile.
Check your CMakeLists.txt that is doesn't contain a set_source_files_properties command that would mess with that property.
If you want to do something with the files, here are two ways to do things:
With add_custom_target you can add them and run custom commands for them when you build the project. Granted that the files have changed.
With configure_file you can easily copy them to a build directory if needed. With the COPYONLY flag.