C++: Add resources to project template - c++

Currently I have a C++ project template that contains some pre-installed images, defined as an array of bytes inside the code. I want to reorganize the project by moving images to resources, but the problem is that .rc script only accepts absolute paths to images, thus I don't quite understand how can I properly use them for project template. All I want is to place image files somewhere inside the project directory, and reference them in project .rc script using relative paths for portability. Is it even possible?
VS2019 Community 16.5.4 btw.
UPDATE1: I need to include my resources at compile time, thus dynamic file management is not an option. I have .rc file in a project and some PNG images inside it. They are defined using absolute paths like IDB_PNG1 PNG "D:\\absolute\\path\\to\\file.png". The problem is that I can't use paths relative to the project, like IDB_PNG1 PNG "\\path\\inside\\project\\file.png", getting zero portability of my resources in the template.
UPDATE2: One possible solution I've found is to use CustomParameter element and write paths in .rc file like IDB_PNG1 PNG "$projectpath$\\path\\inside\\project\\file.png", then set ReplaceParameters=True for .rc file in .vstemplate. But there is only $projectname$ default parameter and I'm not even sure I can do it for absolute path.
UPDATE3 (ANSWER): Thanks to this question I've found there is undocumented parameter $solutiondirectory$ (hopefully MS won't drop it from future releases). So I simply write my resources as IDB_PNG1 PNG "$solutiondirectory$\\$projectname$\\path\\inside\\project\\file.png" and then these paths are automatically updated by the Visual Studio when project is created. Problem solved!

Thanks to this question I've found there is undocumented parameter $solutiondirectory$ (hopefully MS won't drop it from future releases). So I simply write my resources as IDB_PNG1 PNG "$solutiondirectory$\\$projectname$\\path\\inside\\project\\file.png" and then these paths are automatically updated by the Visual Studio when project is created. Problem solved!

Assuming you are using a .rc file in the context of something like an icon image, it is possible. You can just use standard library to link to the image file and then read it byte for byte and load it into the arrays that you were using earlier.
If this is not the right context you could share some code for better understanding.

Related

Copy Visual Studio project settings to new project?

Background
I'm running Visual Studio Community 2015 on Windows 10, writing C++ code.
I have been handed a solution with two projects in it. I need to create a duplicate of one of the projects, but using different source and header files (containing roughly identical code, but located in another place in the file system).
The project that I want to duplicate uses a lot of libraries, and I don't know how that was set up. All I know is that it works for that project, and I need it to work for the duplicate project too.
Problem
The problem I'm having is that at least one of the libraries does not seem to be recognized. This results in code with a red squiggly line under it, no auto-complete, etc. etc.. (This is not relevant anymore, see Edit 1)
Attempted solutions
I have tried creating a new project with the new source files, adding it to the solution, and manually copying project settings by right-clicking on the existing project, selecting Properties, and copying anything that is not set to its default value. This did not work.
I have tried copying the existing .vcxproj files, adding them to the solution, removing old and re-adding new source and header files. This did not work.
In both cases, when expanding External Dependencies in the Solution Explorer, the old project has a much longer list than the duplicate.
I am aware of this question, but the accepted answer relies on knowing which settings need to be changed. I don't know that, and I don't know how to find out.
Questions
So, is there a way to copy the entire set of settings that controls this?
Alternatively, is there a way I can check in the existing project precisely why it is able to resolve a particular external reference, so that I can find out which setting I need to change in the duplicate?
Edit 1
Well, now I feel stupid. I've been fighting this issue for a few days now, but I've made a few incorrect assumptions about the files I have.
It turns out, the second set of header files (located at a new place in the file system) are similar, but not identical, to the old ones. So at first glance, they look identical, and I never bothered to check.
The new header files has #if defined(WIN64) before the relevant #include statements, which of course is why the library wasn't being included.
So, my new question is, what's a sensible way to #define WIN64 without modifying the header file? Where can I put that definition so that it's valid in that header file, without changing that header file?
The correct way to use the same project properties for multiple projects would be not copy-pasting properties between them but to use Property Manager. You should figure out how exactly you original project is configured (note that properties for particular file can differ from project properties) and create a corresponding property sheet(s). Then apply this sheet for the new project.

How do i put raw binary data from file into Windows resource file and extract in into void* in my program? [duplicate]

So I have a Visual Studio 2008 project which has a large amount of binary data that it is currently referencing. I would like to package the binary data much like you can do with C# by adding it as a "resource" and compiling it as a DLL.
Lets say all my data has an extension of ".data" and is currently being read from the visual studio project.
Is there a way that you can compile or link the data into the .dll which it is calling?
I've looked at some of the google link for this and so far I haven't come up with anything - the only possible solution I've come up with is to use something like ResGen to create a .resources file and then link it using AssemblyLinker with /Embed or /Link flags. I dont think it'd work properly though because I dont have text files to create the .resources files, but rather binary files themselves.
Any advice?
Right click the resource script (.rc file)
Choose Import
http://msdn.microsoft.com/en-us/library/saced6x2.aspx
You can embed any "custom" file you want, as well as things like .bmps and stuff VisualStudio "knows" how to edit. Then you can access them with your framework's resource functions like FindResource LoadResource etc...
If you don't have a resource script.
Click Project
Add New Item
Resource Script
http://msdn.microsoft.com/en-us/library/sxdy04be(v=VS.71).aspx
You can embed the binary data as a C language array - no resources involved at all.
An old classic trick.
see for example XD

Libraries VS2015

Good evening
I'm trying to set up a development environment on my newly Boot-Camped Windows 10.
I know how to link the include/lib in VS. On my Mac all my external libraries and include files are at either:
/use/local/ or /opt/local/
I'm wondering whether there is an easy way to do this on windows, or are there a way to force VS to always look in a particular dir?
Cheers
VS has the concept of property sheets which basically are a predefined set of properties for your project. Every C++ project includes by default few property sheets and there's even a special property sheet called Microsoft.Cpp.[Platform].user where [Platform] is either Win32 or x64. By editing the contents of this file you can set the paths for all your projects (or other arbitrary values such as macros).
To edit these files do either of the following:
Make a new CPP project in VS. Go to View->Other Windows->Property Manager. This will show a new pane in the current window and from there you can find the property sheet and edit as you see fit. This approach has the benefit of being more user-friendly as VS provides some nice GUI. Here's one tutorial
Find the files themselves (they are located in %LOCALAPPDATA%\Microsoft\MSBuild\v4.0), open them using your favourite text editor and do your magic. The files are XML-based so it's not awfully difficult.

Is it possible to export a project directly from visual Studio into it's own folder?

I am currently trying to build .net bindings for a very large project that is written in C an C++. The project was recently ported over to Windows, and I might add that is is a big giant mess.
The solution has about 12 projects, which is fine but the directory itself has alot more files than needed,since it includes OS specific source files, demo projects etc.
Also the other thing is the headers and source files are scattered all over the place. I am working on a parser to help me create the bindings for this project, but I am having a heck of a time. Especially when the internal include references are completely off.
The developer did a great job porting this large project to Windows, but isn't very organized and it is driving me bonkers with the issue my parser is having. So the easiest thing to do would be to re structure and put each project in it's own areas.
So as I asked in the title, is there somewhere that I can export each project and it's files from VS 2010(or another tool) so I can begin restructuring the folders? When I have ever needed to do this before in .net it was easy enough to just move the files. In smaller c++ projects I just open up the project file in notepad++ and move each file in the include/source list into different directories and changed the paths in the project file after. The issue with that is it will take way too long, and I have already spent days messing with this project, finding the best way to wrap it, and creating my helper tools.
Can anyone give me some assistance in this aspect?
EDIT:Just to clarify, I would like to export each project into it's own root folder with one folder for headers and one for source files so I can keep things simple.
I'm not sure about a tool for this, but the .vcxproj project files are in XML format, so you can easily extract a list of files from each project. Then you could relocate those files and write their new location back into the project.
Whenever I encounter a serious project mess, I usually end up dragging all the project files into Notepad++ and start doing global search and replace.
I haven't done it on the scale that you seem to be aiming at, where it involves relocating all the sources. You could be in for a rough ride. Fixing up include paths etc could be quite a pain.
I suggest you obtain the file lists (relative paths or whatever) in a simple text format, and then decide whether you want to take the red pill or the blue pill =)

SFML not loading image (Possibly due to placing in wrong place?)

I'm not sure whether I'm doing something stupid or visual studio is doing something wrong.
I've never really used C++ with VS before, but I managed to get SFML working, and now I cannot load images.
This is how I put the image in the project:
However when I write:
if (!tileTexture.loadFromFile("ConceptTile.png"))
return EXIT_FAILURE;
It returns EXIT_FAILURE.
Can anyone give an answer to why this isn't working?
If it helps that png file isn't appearing anywhere in the debug directories, just dlls, exes, and pdbs.
I've looked online to try to find out where I am supposed to put images but I can't find any articles or help no matter what keywords I type.
Make sure you change the file properties within the project to copy it to the output directory. By default (and without further paths given in the string) SFML should look for the file in your working directory. You don't have to add image files to your project, if you ensure they're at the right place. Also make sure to not include them as resources (as SFML won't be able to load them without some additional code).
Open Windows Explorer and move to the folder that contains the C++ files and paste the image there and it shall work or make a folder and change the directory in code, for example, if you name the folder images :
(!tileTexture.loadFromFile("images/ConceptTile.png"))
return EXIT_FAILURE;
and it shall work.