Solved

Visual Basic Exit Codes

Posted on 1997-06-24
6
737 Views
Last Modified: 2013-11-25
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
Comment
Question by:klamerus
6 Comments
 
LVL 7

Expert Comment

by:tward
ID: 1427649
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
 
LVL 1

Author Comment

by:klamerus
ID: 1427650
Edited text of question
0
 
LVL 1

Author Comment

by:klamerus
ID: 1427651
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Expert Comment

by:pdove
ID: 1427652
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
 
LVL 3

Accepted Solution

by:
ChrisLewis earned 100 total points
ID: 1427653
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
 
LVL 1

Author Comment

by:klamerus
ID: 1427654
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now