Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 783
  • Last Modified:

Visual Basic Exit Codes

We are starting a VB application from an existing application that checks for exit codes.

With C we can do "exit(3)" and such, but no such thing exists natively for VB.

We've tried ExitProcess(), but it doesn't seem to work.

Is there another system call or approach that works?
0
Gene Klamerus
Asked:
Gene Klamerus
1 Solution
 
twardCommented:
Try the following API Calls (32bit ONLY):

Declare Sub ExitProcess Lib "kernel32" Alias "ExitProcess" (ByVal uExitCode As Long)

Declare Sub ExitThread Lib "kernel32" Alias "ExitThread" (ByVal dwExitCode As Long)

0
 
Gene KlamerusTechnical ArchitectAuthor Commented:
Edited text of question
0
 
Gene KlamerusTechnical ArchitectAuthor Commented:
We've tried that approach and it doesn't work or we're doing it incorrectly.  I mentioned that the above procedure hasn't been working in the original question.

If you can provide an example of a *.bat file which shows this to work, I'd appreciate it, but for now I'm assuming that it doesn't.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
pdoveCommented:
Dan Appleman, in his 'Visual Basic 5.0 Programmers Guide to the Win32 API' writes this about ExitProcess...'You should avoid trying to close processes using this function.  Do not use on your own VB applications.  Instead, try posting a WM_CLOSE message to the main window of the application you want to close.'That probably doesn't help you a lot, but may help explain why it is not working for you. :)  I wish you luck and will certainly look at any answer you get.
0
 
ChrisLewisCommented:
I don't believe that VB will support an exit code.  The problem is that VB programs aren't in the same format as C programs, they kinda sorta run under the VB runtime environment.  So ExitProcess doesn't really work with VB.

The other thing that you are mentioning is returning the exit code to a DOS batch file (for an IF ERRORLEVEL perhaps...)  .  I don't think windows programs can do this at all.  Dos is Dos and Windows is Windows, and the two really can't talk using exit codes.

Sorry,

Chris
0
 
Gene KlamerusTechnical ArchitectAuthor Commented:
Exit Process is a Win32 call - it works to the extent that it kills the Visual Basic Process.  It should work the rest of the way.
So should TerminateProcess work to kill other processes (and it does).

Perhaps what I need is a better test process than a DOS batch utility.  Or perhaps (since the program calling my program is a DOS utility), what I need is a way to return values to DOS.

As to not getting a return code from a DOS shell - that makes sense.  It is hard to see how a DOS app would be able to evaluate information from the Windows environment.
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now