Solved

Visual Basic Exit Codes

Posted on 1997-06-24
6
748 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

732 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