I have been converting a large application to MFC feature pack over the last month using Visual Studio 2015. I was finished with development and debugging and ready to create a release build. To my horror, the release build had a severe run-time error which I traced using AfxMessageBoxes to the point in the code where the menu bar is created.
CMFCMenuBar m_wndMenuBar;
if (!m_wndMenuBar.Create(this))
{
AfxMessageBox(_T("Failed to create menubar"));
TRACE0("Failed to create menubar\n");
return -1; // fail to create
}
I moved the status bar creation and toolbar creation ahead of the menu bar creation and it still failed at menu bar creation. I turned off optimization in the release build. The debug build works fine.
I have never encountered a release build problem like this before and am at a loss on how to proceed. I could use some advice.
Related
As I often test my binaries inside/outside Microsoft Visual Studio 2017, I want to control the behavior of my code in C/C++ console projects.
One for code for when I run .exe from within Visual Studio in Release mode.
Another when I just click my .exe from Explorer.
What flag or function should I use to know if my .exe was started from inside Visual Studio or not.
What I would like to achive is the:
#if !_RELEASE
system("pause"); // prevents auto shutdown of my .exe in Explorer
// double click
#endif
where _RELEASE is some kind of trait that triggers code in Studio launches,
but not visible in Explorer double click.
What flag or function should I use to know if my process was startded from inside Visual Studio or not.
You shouldn't do such behavior control from inside your program code. That's bad design, and clutters your program code with decisions that should be left on the caller.
I'd recommend if you need different behaviors of your program (e.g. running in background or with visible GUI), this should be controlled with e.g. configuration files or command line parameters.
You can do that for both, Visual Studio settings to specify cmd line parameters, or using a different configuration file, or even a combination of both.
As you seem to insist for a solution of your idea how to fiddle with this in the best way:
You can use the WINAPI functions to iterate through your parent process IDs and check if one of these is matching the "Visual Studio" module.
Here's a Q&A which links to the technique:
How can I reliably check whether one Windows process is the parent of another in C++?
It not exactly solution, but:
Raymond Chen(Microsoft winapi guru*) is most close in spirit to the problem I facing, helping me detect in what mode or circumstances I run my console session.
How can I tell whether my console program was launched from Explorer or from a command prompt?
printf("this process = %d\n", GetCurrentProcessId());
DWORD count = GetConsoleProcessList(nullptr, 0);
if (count == 1) {
printf("I'm the last one!\n");
Sleep(2000);
}
else {
printf("I'm not the last one! %d\n", count);
}
I have to do a programming project for an optimisation class, that has to be written in C or C++. So I'm trying to figure out Visual Studio 2015. I created a blank project, and opened a new C++ file, where I have the following:
#include <iostream>
int main()
{
cout >> "Hello World!/n";
cin.get();
return 0;
}
When I run it, I get a large blank white popup, and nothing else happens, even if I hit various key on the keyboard or wait for several minutes. It looks like this:
If I close the large popup, nothing happens. What Visual Studio refers to as output from build looks like this:
1>------ Deploy started: Project: LinearProgramming, Configuration: Debug Win32 ------
1>Updating the layout...
1>Deployment complete (157ms). Full package name: "53acc796-5708-4314-9034-f2a1f840a4f4_1.0.0.0_x86__eazt3av84y7ym"
========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========
Could anyone please explain to me what's going on? How can I create a simple C++ project in Visual Studio 2015 and run it?
I believe you selected the "Blank App(Universal Windows)" project template, which is like a Microsoft store application. What you probably want is the "Win32 Console Application" template, which creates an application without its own window (and uses the console for I/O).
This is how I create a Win32 Console Application.
Go to File->New->Project...
Select Visual C++->Win32->Win32 Console Application and name the project.
In the Win32 Application Wizard press the Next > button and be sure Console application and Empty project are selected, and then hit the finish button.
In the Solution Explorer right click on Source Files and select Add->New Item...
Select the C++ File (.cpp), name it, and hit the Add button.
After you change the >> to << add the code above and it should run.
The quick answer is to hit ctrl-f5 to open the console. After running your script and showing your output it waits for you to hit a key before closing the console.
I eventually found the answer to the question which can be seen at How to keep the console window open in Visual C++?
I want to ask about cascadeclassfier load doesn't work in release.
I using Microsoft Visual Studio 2010 and OpenCV 2.4.7.
my code:
CascadeClassifier cascade;
if(!cascade.load("D:/data/training.xml"))
{
printf("Error load XML!\n");
return -1;
}
Things i've tried so far:
Tried to specify the path manually using ""
Tried to use / or \ in the path
Tried to give user permission
Tried to call the xml without using absolute path
Tried to use many kind of codes i've found when searching this error
Tried to seperate the xml by creating a new folder for them
Additional Information:
Running in debug mode work 100% perfectly
Running in release while using visual studio trigger a break
Running using the exe created while building only show "Error load XML!"
i really confused right now, so i decided to ask..
Thanks before.
I've had similar problems when switch from Debug to Release Mode. I had copy config from Debug to Release and mistake at Linker > Input > Additional Dependencies. And I had fix this problem by using opencv_world320d.lib for Debug mode and opencv_world320.lib for Release mode.
I have an application that runs in the debug build, but when I start it in the release build, I get this error:
LINK:fatal error LNK1181:Can not open input file 'Qt5Core5.lib'
Try deleting all temporary data created by QtCreator. Has worked for me in that situation.
When I write a program using C++ and I want to run it, I can't catch the console window. I press CTRLF5 and it does not work.
I want the window to stay open and wait, even it finishes executing. Can anyone help me?
Thanks in advance.
http://connect.microsoft.com/VisualStudio/feedback/details/540969/missing-press-any-key-to-continue-when-lauching-with-ctrl-f5
In the older versions it would default to the console subsystem even if you selected "empty project", but not in 2010, so you have to set it manually. To do this select the project in the solution explorer on the right or left (probably is already selected so you don't have to worry about this). Then select "project" from the menu bar drop down menus, then select "*project_name* properties" > "configuration properties" > "linker" > "system" and set the first property, the drop down "subsystem" property to "console (/SUBSYSTEM:CONSOLE)". The console window should now stay open after execution as usual.
try using system("Pause"); as the last line on your code (before the return of your main function)
Ctrl+F5 should work. Just in case, if you have the source of your program, add the following just before the closing brace of main.
int x;
cin >> x;
the program will wait for you to enter some value.
If you want a breakpoint to be triggerred in debugger, do simple F5 instead of Ctrl+F5, after putting a breakpoint on the relevant source line (assuming the source/debug symbols are available)
Sorry to say, Ruba, but it looks like Microsoft removed this nifty little feature when moving from VS2008 to VS2010.
I can't find anything on MSDN, the web in general, or VS options to turn it back on.
My advice is to bypass the environment altogether for testing your application. Simply open a cmd.exe window in your runtime directory (debug or release or whatever), build the executable within the IDE then switch to the command window and enter testprog.exe to run your program.
Make sure you include any required command line parameters and, after you've entered it the first time, you can just use the up-arrow to retrieve the last command.
Yes, it's a bit of a pain but, until someone comes up with a better solution, it's probably the best way to ensure you see all the output while ensuring the program has shut down completely.
Just set a breakpoint at main()'s closing curly brace if you want to see the console after the program is finished.
You should create VS 2010 C++ Projects as below:
New project -> Visual C++ -> Win32 -> Win32ConsoleApplication
In this way you will be getting "Press any key to continue..." when you run program with ctrl+F5, as it was in VS 2008.
EDIT :
New project -> Visual C++ -> Win32 -> Win32ConsoleApplication -> Next -> Check 'Empty project' -> Finish = what you actually need.