Import idl files into Visual Studio (C++)? - 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.

Related

How to connect single.c/.h files to cmake project?

So, I'm new to cmake and have some troubles. I have simple cmake project that contains a few .h and .c files. I've searched C code at github which consists of only one .h and one .c files. And i want to use some functions from this pack, but i don't want to put this file in my project directory. I want to keep them somewhere outside the project directory. So, how to connect them to project, how to make header visible for project and use #include "name.h" for watching and
and using available C functions .c/.h pack in my project.
Create some other directory in your project, such as misc/ and put the files there. Then use it in your code via "/misc/name.h"

How to use Resource.RC file in Visual Studio

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

How do I share C++ source code files between projects in Visual Studio?

I'm writing a cross-platform application. One version will work under Win32 and the second on Windows Phone.
I'd like to reuse my C++ core - especially that there are no platform dependencies inside, STL only. I order to do so, I want to use the same source files in two projects: static Win32 library (.lib) and Windows Phone Component (C++/CLI).
How can I configure these two projects to use exactly the same source and header files?
OK, let's take an example. Let's say, that I have project:
MyApp.Library [win32 lib]
myClass.cpp
myClass.h
This library is compiled to .DLL file and then imported in a Win32 application:
MyApp.Win32App [win32 C#]
Since Win32 is not compatible with Windows Phone on the binary level, I cannot use that library directly. But since the library uses only STL, I can create a Windows Phone component, put all its sources there, and build.
MyApp.Component [Windows Phone component]
myClass.cpp
myClass.h
I want these two files to be exactly the same ones as used in the library. How should I organize the project to achieve this effect?
You can add source code from a common location to multiple projects. I do that a lot; I have code in a common directory that is at the same level in the directory hierarchy as most of my project files. It's simply a matter of adding .h and .cpp files from the common directory to your various projects.
I did notice that VisualStudio gets a little cranky and difficult if you use a network drive for common source, so I don't do that. But so long as all of your source code is on local disks, and the IDE knows where to find them, there is no problem having the same source file in very many projects.
one way is to put all .hpp and .cpp files into a seperate folder - call it "Shared".
Then add an additional include Directory inside your solution configuration property - this directory must be a relative path.
Then add ONLY the .cpp files relative from that shared folder into your project
NB! If you have include "stdafx.h" inside your .cpp files in the Shared folder, then comment those out.

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.