I have a .manifest file which is linked with a .exe program file so that it asks for admin privileges when opened. Now it is a separate file called program_name.exe.manifest which is is the same folder as program_name.exe. Is there any way by which we can embed the manifest file into the .exe file so that it can be one single file instead of two.
BTW the program is created using C++
Yes. Declare the manifest as a resource and then just build the resource object file and link it to your exe.
In your resource.rc file, define your manifest resource like so:
IDR_RT_MANIFEST1 RT_MANIFEST "program_name.exe.manifest"
In your resource.h file declare it with the value 1
#define IDR_RT_MANIFEST1 1
Build the resource file with windres: windres resource.rc -o resource.o
Link the resource when building your project: -l resource.o
.........................................................................
If your're using Visual Studio you don't need to build it explicitly, but there are 2 options which should be set beforehand:
1) Project > Project_Name Properties > Configuration Properties > Linker > Manifest File -> Generate Manifest set to No
2) Project > Project_Name Properties > Configuration Properties > Manifest Tool > Embed Manifest set to Yes
Also add your manifest file to your project as existing item.
If you are using windows CL, like powershell, try
program_name.exe –manifest program_name.exe.manifest -outputresource:program_name.exe;1
That should do the trick.
Related
I have a Visual Studio project (Project 1) that generates an executable file (a.exe). I have a project (Project 2) that runs the executable from project (Project 1) multiple times with different command line arguments. On the command line I can run:
C:\filepath\Solution\Project1> a.exe //command 1
But I cannot run:
C:\filepath\Solution\Project2> C:\filepath\Solution\Project1\a.exe //command 2
Because the .exe file depends on the surrounding file hierarchy.
In Project 2, I can run a system call to execute command 2, but I hit hierarchy/location dependency issues. The Solution structure is as follows:
Solution
--> Project 1
--> a.exe
--> Project 2
--> main.cpp // this will run system call to command 2
Is there any way I can get around this without changing the a.exe file?
In Project2, how are you executing Project1's .exe? If you set the Current Working Directory (CWD) to the folder where Project1's .exe resides, it should work as expected:
var p = new ProcessStartInfo(#"C:\Project1\bin\project1.exe");
p.WorkingDirectory = #"C:\Project1\bin";
Process.Start(p);
If this doesn't work for whatever reason, you can simply copy the entirety of Project1's binary output and the associated file structure into Project2's output folder. There are two ways to do this:
Option 1 (preferred): Add the binary output of Project1 to Project2. To do this, right-click on the Project2 node in Solution Explorer, select Add | Existing item... In the "Add Existing Item" dialog, change the file type to "All Files". Navigate to Project1's bin folder, select the Project1 .exe and all dependencies, click the "down arrow" on the right side of the "Add" button, and select "Add as link". In Solution Explorer, select the newly-added file links in Project2, and in Properties change "Copy to Output Directory" to "Copy if newer". For each subfolder in Project1's bin folder, you must use Solution Explorer to create a new corresponding folder in Project1, then repeat this process for all files in that subfolder.
Option 2: Create a post-build step to copy Project1's binaries and surrounding folder heirarchy to Project2's bin folder. To do this, right-click on the Project2 node in Solution Explorer and select Properties. Go to Build Events, and enter a Post-build command line such as the following:
xcopy "C:\Project1\bin\" "$(TargetDir)" /S
Option 1 is preferred because with Option 2, external tools are less likely to realize Project 2's dependency on Project1. In both cases, Project2 must be updated to run the Project1 .exe directly from Project2's output folder.
Good luck!
I'm trying to configure FASTMM4 for Builder C++ 6 and the steps I followed are;
Downloaded zip from sourceforge.
Under the Project -> Options -> Linker menu I unchecked "Use Dynamic RTL".
Unzipped the contents at C:/tools/FASTMM and added FASTMM4.pas file to my test C++ VCL project.
Simply compiled the unit from Project menu and got a new FastMM4.hpp file in FastMM folder.
Included FastMM4BCB.cpp file in my project and also wrote #include <FASTMM4.hpp> on the top.
Added path to FastMM_FullDebugMode.dll and FastMM_FullDebugMode.lib and moved FastMM_FullDebugMode.dll to the Bin folder in Builder C++ install directory.
Enabled the line {$define FullDebugMode} from FastMM4Options.inc.
Did I miss anything? why do I have the following errors?
I found the instructions in FastMM4BCB file itself and I got it working.
Usage:
Copy FastMM4BCB.cpp, FastMM4.pas, FastMM4Message.pas, FastMM4Options.inc,
and FastMM_FullDebugMode.lib to your source folder.
Copy FastMM_FullDebugMode.dll to your application's .exe directory (if you
intend to use FullDebugMode).
To your project, add FastMM4Messages.pas first, then FastMM4.pas, then
FastMM4BCB.cpp. On compiling the .pas files, .hpp files are created and
imported by the subsequent files.
Add USEOBJ("FastMM4BCB.cpp") to your project file, BEFORE any other
USEFORM directives.
Under the Project -> Options -> Linker menu uncheck "Use Dynamic RTL"
(sorry, won't work with the RTL DLL).
FastMM will now install itself on startup and replace the RTL memory manager.
I have included an obj(Wavefront .obj file) file as a resource with the attributes Build action: None and Do not copy.
How can I access these files from a c++ file later?. The resource file is in a c# project which is being compiled to an exe file. And the project where I want to access these resources are from a dll file?
If I change to Always copy I can access the file using the normal way:
ifstream file("Resources\\file.obj");
You can solve this by right-clicking your ".obj" resource file. Go to "properties" and make sure "Exclude From Build" is set to "Yes."
I have found a solution for this, but it only works if you use .DEF files (I don't).
I wonder if this can be done without .DEF files.
Project > Properties. Then Configuration Properties > Linker > General > Output file. Here you should have something like: $(OutDir)\$(ProjectName).dll just put $(OutDir)\$(ProjectName)d.dll
Since you are using Visual Studio, you can set the output file path through the project's property pages:
Properties --> Linker --> General --> Output File
We don't have a Qt plug-in installed for MSVS, and it makes me wonder how/whether it is possible to load resources (images, etc) to the application.
Yes, you can load ressources.
Unfortunately, the qrc Editor which create qrc files is part of the Qt Addin for VS...
But you can create this xml file by hands, for the format see here
Once the qrc file created, you have at least two possibilities :
A) Use qmake
Add a reference to your qrc file in your pro file :
RESOURCES = ApplicationResources.qrc
Regenerate your vcproj from your pro by using qmake
qmake -tp vc
B) If you don't generate your vcproj file from your pro file, you can :
Add manually your qrc file in your solution, for example in the following path :
Resource Files/Res/ApplicationResources.qrc
Add the following commands in the properties of the qrc file in visual studio :
command line : $(QTDIR)\bin\rcc.exe -name ApplicationResources res\ ApplicationResources.qrc -o $(IntDir)\qrc__ ApplicationResources.cpp
Description : RCC res/ApplicationResources.qrc
Output : $(IntDir)\qrc__ ApplicationResources.cpp
C) You can also use an external binary resources file
The command line :rcc -binary myresource.qrc -o myresource.rcc
In the application, you have to register the resource file :
QResource::registerResource("/path/to/myresource.rcc");
For using resource file in the source code see the doc
However, like cheez, I also suggest using qmake and pro file and do not edit properties by hand in Visual Studio...
Hope this helps !
Use the qrc executable to generate a cpp file which you can include in your project:
/usr/local/Trolltech/Qt-4.5.1/bin/rcc -name core core/core.qrc -o build/release/core/qrc_core.cc
See http://doc.trolltech.com/4.0/resources.html
However, I strongly suggest using qmake or some other build system to automate this for you.