Sign in to follow this  

EXE OK within Visual C++ but crashes outside

This topic is 4207 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm working with Visual C++ 2005 Express to compile and run my application. No problem when I launch from the run button in Visual, but when I try to launch it directly by double-clicking on the .exe file, it crashed with a basic Windows error saying the application encountered a problem and must close. It could be caused by some compiler settings by I don't know which ... Any idea ? Thank you, K.

Share this post


Link to post
Share on other sites
Maybe some files that you load inside your program are missing. Your program can't find them and you haven't done error checking(program continues executing without them).
Probably are your data files somewhere in sources dir, but are missing in debug dir.
Use full paths when you load your data.

Share this post


Link to post
Share on other sites
Thanks for your answer, but that is not the problem:

I modified my code to have:



int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
return 0;
}




And the error is still there !

SO the program does not have to do anything else than to quit ...

K.

Share this post


Link to post
Share on other sites

int main()
{
return 0;
}




has the same result ...

It crashes = pop-up window with a message saying my exe encountered a problem and must close, with buttons to send the error report or not (also a link with click here to access the report details, but nothing I can understand in it).

Of course, my application does have a lot of global classes, but having said that, why can it work differently in Visual than from exe file ?

Thanks,
K.

Share this post


Link to post
Share on other sites
When he said global classes he meant global instances of those classes. That is, do you have global variables that are going to be constructed and destructed (in essence doing more than just a return 0)? If you do, then that's where the problem lies: it's probably a constructor trying to load a file or DLL that isn't in the right directory.

Share this post


Link to post
Share on other sites
OK, that could be the problem.

Since I can know the dll I include in the project via the compiler/project settings, how can I specify the "path" ?

It's a DirectX application (with DX specific global classes), so I need a number of external files, I thought the executable file "knows" where it has to look for them ...

Thanks,
K.

Share this post


Link to post
Share on other sites
Executable file "knows" to look for dlls in same path where the executable itself lies, "c\windows\", "c:\windows\system\" and "c:\windows\system32\".

Share this post


Link to post
Share on other sites
I've never seen int main() work in a Win32 project. If you had WinMain you cannot replace it with main() and have it still compile in VS. It's never worked when I've done it. Could something else be up?

Share this post


Link to post
Share on other sites
I had a similar problem when one of my program crashed on entry. It drived me mad. On one second it worked on other when I tried to debug it to see when crash occured it pointed that error is on program entry???
Anyway I figured out what was the problem. It was Ati tray tools [smile]. Program crashed when some options were enabled specialy FPS display. Maybe that is your problem too.

Hope that helps...

Share this post


Link to post
Share on other sites
Quote:
Original post by Kiristu
OK, that could be the problem.

Since I can know the dll I include in the project via the compiler/project settings, how can I specify the "path" ?

It's a DirectX application (with DX specific global classes), so I need a number of external files, I thought the executable file "knows" where it has to look for them ...

Thanks,
K.
This is what error handling is for [wink]

When you start your app from within MSVC, MSVC sets the working directory to be your project folder. When you run the exe itself, the working directory will be your Debug or Release folder, which probably doesn't contain the resources you're trying to load.
One quick and dirty way you could find where the problem is is to delete or move the resources temporarily, and then run the app in MSVC. It should break to the debugger on the line that causes the crash.

Share this post


Link to post
Share on other sites
I was quite lazy on error handling, but I don't include any resource in my project. All textures and other things I need are specified with the full paths.

I also tried to move the EXE file to the source folder by it still fail.

Any idea of the folder where it would work ?

I firstly developed my application with Visual C++ 6 (I had to change because of some bugs within VC6 corrected in 2005 Express), and I was able to launch the EXE directly from the Debug folder.
This is why I thought of a setting problem.

When I run on debg mode, I can see a lot of loaded DLLs (with message: no symbol was loaded), but some of them are not related to my project (Logitech SetPoint for example).
I can also see these ones:
C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9\comctl32.dll
C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_0de06acd\msvcp80.dll

and I really don't know what it is ...

K.

Share this post


Link to post
Share on other sites
you could try a remote debugging session (on your local machine, so it isnt actually 'remote') This is how I often adress those kind of problem (solution running fine in the IDE but crashing when outside the IDE)

If you dont know how to, its quite simple. Launch your program, then go to VS and choose debug:attach to process. Select your executable's process and attach it (it's preferable that you exe is a debug build)

The fact is you application will not wait for you to attach a debugger on it, so the technique most people use is to add an infinite loop at the begining of the main, like:
bool bWait = true;
while(bWait)
sleep(1000);

Then in the debugger, you can manually edit the value of bWait and allow the programm to continue execution. (BTW, does someone know a cleaner way of doing that?)

However, all this might not be helpful for you since it looks like your crash is caused by stuff initialised before your main. Maybe you could sneak the infinite loop before your globals are initialized (I'm not sure if this is possible, something like a pre-main ?) or change your design to avoid using global instances (using global pointer to these instances could be slightly better, at least you could control the order of construction, it would be easier to debug as well, and perhaps you wouldnt have to change a lot of things in your code)

I'm not sure that would help in your particular situation, but more generally when a program crashes when run outside of the IDE, this method can be helpful. A program doesnt have to be run from the IDE to be debugged.

Cheers
Janta

Share this post


Link to post
Share on other sites
Thanks Janta !

What I do to force the debugger to stop before the WinMain starts is to create a Debug class with a constructor containing the infinite loop ...
After that, I instanciate a global variable of that class at different places to see is the program launches or stop etc ...

In my case, the problem has mysteriously disapeared during my tests, and the exe file finally worked after dropping the debug class (I thought of a DLL loaded once that makes it work, but it still works after reboot, strange).

Thanks again for the tip, it will surely help again !

K.

Share this post


Link to post
Share on other sites

This topic is 4207 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this