How to know the meaning of a Thread Exit Code

Hi...

My applicacion when it is shut down, is exiting with 2 exit codes...

-1 and 2

This is a Dialog Based application with an OCX Tab Control.

Why my thread isn't exiting with exit code number = 0?

Actually, messages in debug window are:

The thread 0xFFCA0331 has exited with code -1 (0xFFFFFFFF)
The thread 0xFFCA0C25 has exited with code 2 (0x2)

What does it mean?
thanks

Skel
skelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mikeblasCommented:
The thread exit code is arbitrary. Whoever wrote the thread is returning an exit code by their own design. There's no definitive set of meanings for the codes.

In fact, many developers don't have anything to return because the thread communicates with its owner by a more robust means, and therefore the value is completely meaningless.

No value categorically means failure, none reliably means success.

..B ekiM
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skelAuthor Commented:
Yeah... but the thread in this case is that made by Microsoft in their MFC. I'm not using anything else from other vendor. Only Microsoft OCX Tab Control and MS Form 2.0 CommandButtons. The only thread in execution is my own thread.

I have only created a Dialog based application by using the wizzard and start placing controls, nothing else. I think something is wrong with ActiveX controls, because when I place a CommandButton, Debug window display the message that there is an Access Violation.

Since these exit codes are from Microsoft, I think they are well documented, but I searched in MSDN but I haven't found anything. Knowing the meaning of such codes, I will be able to find where is the error.

Skel
0
mikeblasCommented:
> but the thread in this case is that made by Microsoft in their MFC.

No, it's not. MFC doesn't directly create any threads.

MFC may indirectly create other threads by calling APIs in Windows that use extra threads. Most notably, the common dialogs use an extra thread or two.

 > Since these exit codes are from Microsoft, I think they are well documented

Again, they aren't. Thread exit codes in threads you don't own are an implementation detail.

 > Debug window display the message that there is an Access Violation.

This is the error that you're trying to track down? Using the debugger, you'll be able to figure out what's going wrong. If you want to post the exact message you get, along with a stack trace (with symbols) I can probably start giving you advice about that. But it's always faster for someone to do their own debugging--there's always information someone who's remote just doesn't have.

The exit code of the thread is not a clue that is valuable to you.

..B ekiM
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

skelAuthor Commented:
Thanks for your comment, but this is very strange, I have only placed controls over the dialog, without any code yet. This is out of my hands because I'm only using common controls (OCX) and the standard controls (in tool bar). For example, that fact of Access Violation ocurres only when I place CommandButtons, but not with all CommandButtons in the form. I tried to follow the creation of the dialog but I will get crazy going to all the branches until I see the message in Debug Window.

And with respect to the exit code, I tried to trace into the MFC after ExitInstance method and I cannot realized the exact moment when the thread exit code was different from 0. I only can see that the Run() method returns 2 as the exit code.

How can I show you the stack trace since I cannot isolate the problem? I only see the message in debug window when the dialog is finally shown (Access violation error) or the application is finally exited (Exit Code). If I could find exactly where in the code is the problem, I'm sure I will be able to solve it.

A thing I will try tomorrow is to search for the TRACE or TRACE0 macro with such messages. Maybe I will find the conflicting point that way.

Skel
0
mikeblasCommented:
> How can I show you the stack trace since I cannot isolate the problem?

That makes isolating the problem a priority, huh?

Like I asked before, can you please provide exact copies of the messages you're getting? That way, I can see what's happening and provide exact suggestions for helping you--even though I've already answered your original question.

I don't like guessing games.

..B ekiM
0
skelAuthor Commented:
I think this doesn't help, but as you've requested it, here it is: (these are ALL the messages)

Loaded symbols for 'C:\WINDOWS\SYSTEM\MFCO42D.DLL'
Loaded 'C:\WINDOWS\SYSTEM\COMCTL32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\SHLWAPI.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\SHELL32.DLL', no matching symbolic information found.
Loaded symbols for 'C:\WINDOWS\SYSTEM\MSVCRTD.DLL'
Loaded symbols for 'C:\WINDOWS\SYSTEM\MFC42D.DLL'
Loaded 'H:\Trabajos\Programacion\FingerAccess\FingerMan 3.0\FingerMan\ENCRYPT.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\OLE32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\OLEAUT32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\ADVAPI32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\GDI32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\USER32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\KERNEL32.DLL', no matching symbolic information found.
Loaded 'H:\Trabajos\Programacion\FingerAccess\FingerMan 3.0\FingerMan\FSERVER.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\IMM32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\INDICDLL.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\WSOCK32.DLL', no matching symbolic information found.
Loaded 'E:\PC-cillin 98\JavaHook.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\WS2HELP.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\MSVCRT.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\WS2_32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\WININET.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\MSWSOCK.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\COMDLG32.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\MSCOMCTL.OCX', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\OLEPRO32.DLL', no matching symbolic information found.
Loaded 'C:\Program Files\Iomega\Tools\IMGHOOK.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\FM20.DLL', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\riched20.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\SYSTEM\FM20ESP.DLL', no matching symbolic information found.
Warning: skipping non-radio button in group.
Warning: skipping non-radio button in group.
Loaded 'C:\MOUSE\Genmm.dll', no matching symbolic information found.
The thread 0xFFCA36AD has exited with code 2 (0x2).
The program 'H:\TRABAJOS\PROGRAMACION\FINGERACCESS\FINGERMAN 3.0\FingerMan\Debug\FingerMan.exe' has exited with code 2 (0x2).

Cheers
Jaime
0
mikeblasCommented:
The thread exit code means the thread exited.  Where's the access violation error message you've been talking about?

..B ekiM
0
skelAuthor Commented:
That exit code is what I actually want to fix. And I don't know why the Access Violation Error stopped occuring, thanks god!! :)

Let me tell you why I'm so worried about that exit code. A code different from 0 means that something abnormal happened when the program exited. This program is intended to be selled and I don't want the program to crash in some circumstances. I don't know if this problem will be important or not when I finish the program (I'm just starting it), but what if this problem get increased?

Thanks
Skel
0
skelAuthor Commented:
This is the access violation error when I show a dialog containing CommandButtons ActiveX controls:

First-chance exception in FingerMan.exe (GDI32.DLL): 0xC0000005: Access Violation.
First-chance exception in FingerMan.exe (GDI32.DLL): 0xC0000005: Access Violation.
0
mikeblasCommented:

 > A code different from 0 means that something
 > abnormal happened when the program exited.

Says who?  Look: I'll say it again, and hopefully I'll finally penetrate you: the return code from a process or a thread is completely arbitrary. If you execute this code:

void main()
{
   return 37;
}

you'll find that the process and the main thread itself both exit with the code 37. The code means nothing. Nothing here went wrong, even though the return value was not equal to zero.

How much clearer can I make it for you? I'm tired of repeating myself, and I'm already typing as slowly as possible.

 > This is the access violation error when I
 > show a dialog containing CommandButtons ActiveX controls:

Yeah. That tells me nothing. You need to debug that.

1) Provide a stack trace for the exception when it occurrs.
2) Show us source code for the call surrounding the function which caused the exception.

..B ekiM
0
skelAuthor Commented:
Yeah.. I understood since the first time you wrote it, I'm not silly, but is there something bad to know the meaning of that code? ALL programs I have made until now return 0, so it was very strange for me that it return a code different from 0, specially when I ONLY place controls on a form, without any own code.

When I programmed for DOS, I used to return 0 when all is OK, but other code when something happen to tell the calling process what action to take. For example, if the program tried to open for reading a missing file, I made the program to exit with a code different from either 0 or 1. Both numbers where the standard I saw in all books where I studied.

When the program returned -1 usually meant something was wrong. As you saw, one of my threads returned -1 and the other returned 2. Of course this is arbitrary for a programmer, but  a good programmer has to follow some stardards. Suppose I implement a class to be sold and the methods of that class return FALSE (0) when it was OK and TRUE (1) when there was an error in the method (that it might be arbitrary too). That will confuse the programmer since it is accustom differently.

I agree to think that 2 maybe isn't an error, but it's clear that it means something. A programmer never will use a code different from 0 because "he wishes" without any special reason, or at least a good programmer. I repeat, I only placed controls made by Microsoft, and I expect the same convensions used by all Microsoft programs.



And about that Access Violation, I cannot place the surrounded code here, because there isn't code, I only place some OCX commandbuttons without any code, and as you see, the access violation occurres in GDI32.DLL. Fortunately I can continue executing the program without crashing. That access Violation occures when the form containing that controls are shown, not only the first time, but all times.

I'm wondering if I am being clear enough.. but I don't speak English well, so sorry.

Skel
0
mikeblasCommented:
> but it's clear that it means something.

Sure. It's the value the thread's controlling function returned. I keep telling you this, and this is the last time I'll say it: you don't know what that value means, and there are no documented standards for the meanings.

I've answered your original question three times over, and provided lots of ancillary advice for your follow-up questions.

You've completely worn my patience out.

I can't teach you how to fix your program--you need to find out what's causing that unhandled access violation exception. You're going to do that by debugging. As I've said before, the result tells you nothing unless you have the source code that returns that result and can see the result really means something. There are no standards.

Good luck with your project.

..B ekiM
0
skelAuthor Commented:
Finally I was right and as always, I found the answer of my questions by myself.

That exit code really means something.. do you want to know what it is? it means that the Dialog Based application was exited by mean of the close button (on the upper right corner). If that application is closed by mean of ESCAPE key, the exit code will be 27 (ASCII ESC code), if it is closed by using Enter Key, exit code will be 13, and so on. If it is closed the normal way, that is, by pressing the OK button (or Cancel button), the Exit code will be 0.

Fortunately that wasn't an error condition but I always want to have ALL clear, without leaving anything at random, that is a habit acquired in the University.

Finally that code wasn't arbitrary :)

Skel
0
mikeblasCommented:
> Finally that code wasn't arbitrary

Of course it is.  The return code of a dialog-based application won't _always_ show which key was pressed to close the application.

Look at your own sample: you said you were getting the exit code 2.  What's that mean?  That someone closed the application by pressing CTRL+B ?

Besides, you asked about the thread's exit code--not the exit code of the application.

A thread or an application can return whatever it wants, and can decide the code means whatever it wants.

You're not "right": you're suffering from a poor understanding of what's happening here.

In fact, the return value of a dialog-based AppWizard-produced MFC application is whatever was lying around in the wParam parameter for whatever the last message the application processed. Sometimes, that's WM_KEYDOWN. Sometimes, it's not. Sometimes, WM_KEYDOWN might trigger another messgae being sent and you don't know what that'll be.

If you wanted it to be something specific, you'd override ExitInstance() and make sure you return the value you mean to describe the situation you're talking about. But, certainly, in your case, there's no code there and the value isn't guaranteed to mean anyhting in particular.

..B ekiM
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.