Code working only when debugging - c++

I'm using Visual Studio 2012 Express for Desktop and I have a code based on Winsock client-server. The problem comes when running the program. One functionality of the program works ONLY when debugging. Why could it happen? Any help is appreciated.

For Visual Studio, if you compiled using the usual debugging defaults, there are things that are done at runtime that are not done in release mode.
One is that variables are initialized to 0 (or their default), while release mode they are left uninitialized. So it could be that uninitialized variable(s) are being used, and you don't see the issue when running the debug version.
Your best bet is to debug the release version. Then you can use the integrated debugger in the release build of your application.

Related

Visual Studio C++ But Without Dependencies [duplicate]

I created small aplication, copied exe from debug, copied textures, fonts in same folder as my exe is. In my computer, with visual studio installed i dont have any problem with running this, but on other computer i can't run this application, beacause of mvcp100d.dll(system don't see this). Is there any possibility, to run this exe in any other cumpter?
To prepare a computer to test the debug version of an application that is built with Visual C++, you have to deploy debug versions of the Visual C++ library DLLs that the application depends on. -from http://msdn.microsoft.com/en-us/library/aa985618.aspx
NOTE: Debug versions of MSVC runtime are not redistributable.
Unless you need the debug version, I would build in release mode. Not only can that be distributed, it's usually faster also. It doesn't seem to me that you are doing anything with debugging that application.

How to execute MFC application on any pcs

I'm trying to release the mfc app which can execute without installing visual studio 2015.
First, When I'm on google, this suggested that I can execute like above by installing vc++ redistributable package.
So I've installed packages but it doesn't work.
And I got the error message. The message is like - "The program cannot start because of missing mfc140ud.dll. ...."
Second, someone said that the release app instead of debug mode can be executed without visual studio.
So I compiled the app on release mode, then I didn't get the error message but it doesn't executed. What's wrong with this?
What can I do?
You distributing a DEBUG version of your application. You can tell that by the name of the DLL it says it can't find. The "d" suffix of "mfc140ud.dll" indicates it's looking for the DEBUG version of the MFC libraries. I don't think that the redistributable contains debug version. Nor should it.
Try releasing a RELEASE build to your clients.
Your application don't run on other PC because is the debug version, compiling to release and distributing on other PC having the visual studio redistributable package will do.
If you want your application to run not depending on the mfc140u.dll you can simply static link your application with MFC. This is easily accomplished going into your project properties.
Your application exe will be bigger but you won't have to bother with these kind of errors anymore. Please note that while this method works on debug too you better not distribute debug code on other machines for a number of reasons.

C++ equivalent of Debugger.IsAttached() [duplicate]

I use stackwalk64 to generate stacktraces for C++ in visual studio 2008 using the latest symchk.exe and dbghlp.dll. This works fine when I'm running the standalone exe. However, when the debugger is attached I deadlock visual studio. I previously had a workaround where I downloaded all of the system32 symbols to disk and this worked well, but a recent update seems to have broken my workaround even though I updated the symbols. Ideally I would like to determine if the visual studio debugger is attached (it will only ever be the VS debugger) so I can turn off my stack traces in that case. Thanks for any help.
Use IsDebuggerPresent and possibly CheckRemoteDebuggerPresent

Why won't my C++/Win32 project work outside of Visual Studio?

I have a rather large project I'm working on in C++/Win32, and now that I'm nearing completion, I wanted to start testing it on other machines. My project works great in Visual Studio - either in Debug or Release mode. However, if I try to run either executable from its build directory (with all of the supporting files in place) they crash. I tried using the debug feature provided by visual studio, and it opened malloc.c, saying that a heap has been corrupted. If I had a memory leak or something somewhere, why wouldn't I be getting this error when I run my project from Visual Studio? I could use some pointers on how to debug what the problem might be.
I don't think that is due to memory leak. It has happened to me too when I tried to copy only the compiled executable but not depend libraries. So just check whether all depend libraries are available in other systems too.

Install msvcr80d.dll

For reasons beyond my control, an app I am working on deploying needs to use the debug version of the Microsoft Visual C++ 2005 library. I tried to register the msvcr80d.dll with regsvr32.exe and it fails. Is there a work around to get the debug libraries to register?
They shouldn't be registered, and the debug version isn't redistributable. It's best to fix the build of your project to get rid of the debug build, because you can't deploy it this way.
this is the visual studio run time library debug version. besides being non optimized this dll contains additional code to detected various run time errors. you should not use that for distribution, in addition to being slower your application might display all sorts of ungainly debug message boxes. skip the shortcut and recompile a release version.
This dll do not export DllRegisterServer and so cannot (and should not) be registered with regsvr32
If you install VC++ 2005 Express edition on each target PC that should include the non-redistributable DLLs. Then maybe you can deploy your app on those PCs.