Microsoft indicates that VB6 doesn’t support ExitProcess (to exit and return a value).
However, it indicates that this call can fail under certain circumstances (if a thread hasn’t been completed, etc.)
so I’m wondering whether this call will work OK (consistently 🙂 as long as you obey the caveats in the article.
I could go a step further and call ExitProcess() from the Sub Main or Form which stared the app.
Update: after some more reading (I really did research this a bit before asking ) I found a suggestion to use the TerminateProcess API instead. I’m investigating that option.
Any thoughts?
Best option is probably to create a Sub Main entry point anyway, and call
ExitProcessfrom there rather than from a class or form. Or (which is what I’m doing) callExitProcessfrom the Form Unload event and have a Main entry point like:Then:
So the
ExitProcesswill be the last bit of code you execute.It’s not going to be pretty and you will probably leak some handles and whatnot, but NT4 and higher are fairly good at handling that anyway. In other words, drive your application from Sub Main and call the API before you exit from there.
Note: this was posted by Kprobst but it was at the end of a post that had an incorrect answer. So I’m reposting it here for clarity.