views:

36

answers:

2

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?

+1  A: 

You could use Karl Peterson's method of creating a console app from VB6? Then use Con.ExitCode = 1 (as shown in the second sample).

He's distributing a free add-in vbAdvance that helps you build console apps.

MarkJ
A: 

Best option is probably to create a Sub Main entry point anyway, and call ExitProcess from there rather than from a class or form. Or (which is what I'm doing) call ExitProcess from the Form Unload event and have a Main entry point like:

Sub Main code Launch Form Exit Main

Then: Form_Unload code ExitProcess End sub 'Form_Unload

So the ExitProcess will 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.

Clay Nichols