Results 1 to 5 of 5

Thread: VB app returning user defined ExitCode

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Posts
    5
    Hi all,

    Perhaps there is someone who has knowledge about how the following is done. I want to terminate my program with an exit code I chose.

    This is needed for my program because my program is called by another which should exit itself when a specific exit code is returned by my app.

    I thought it would be possible by using the ExitProcess Api call. But it crashes the program with an illegal operation. (Though this happens at the end of Sub Main)

    What should i do in my application to sucessfully return my own specified exit code ?

    Greetings,

    Dunebuggy

  2. #2
    Guest
    Try this:


    Code:
    Private Declare Sub ExitProcess Lib "kernel32" _
    (ByVal uExitCode As Long)
    
    Private Declare Function GetExitCodeProcess _
    Lib "kernel32" (ByVal hProcess As Long, lpExitCode As _
    Long) As Long
    
    Private Declare Function GetCurrentProcess _
    Lib "kernel32" () As Long
    
    
    Private Sub Form_Load()
        'KPD-Team 1999
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        'end this process
        ExitProcess GetExitCodeProcess(GetCurrentProcess, 0)
    End Sub

  3. #3
    Guest
    The PostQuitMessgage function is used to exit an application. You can specify and exit code as well.
    Code:
    Private Declare Sub PostQuitMessage Lib "user32" Alias "PostQuitMessage" (ByVal nExitCode As Long)
    Usage:
    Code:
    PostQuitMessage(0)

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Posts
    5

    Talking

    Thank you both for replying.

    I forgot to tell you that this illegal exception only occurred when i ran the application from the vb6 ide.

    PostQuitMessage with an argument worked better as it did not trow an exception. But it also stopped my VB6 IDE.

    However i do understand why this is happening. The actual process being quit is not the application but the vb6 IDE. Both your solutions terminate the vb6.exe process )

    I guess the vb6 IDE does not run the application as a seperate process but as a thread of some sort from the vb6 process. Don't pin me on this assumtion as i have not yet verified this.

    After building the application and running it the code worked using PostQuitMessage.

    Matthew: Sorry to tell you but you solution didn't work.

    PostQuitMessage worked like a charm.

    Question : How can this be made working when running from the IDE as to running as an .exe

    Thanks,

    Dunebuggy

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Posts
    5
    Sorry.. I spoke too early as that PostQuitMessage doesn't set the return value correct.

    <code>
    PostQuitMessage 1
    </code>

    Still ends the process with 0

    Perhaps because PostQuitMessage only works on the thread it is called upon.

    <code>
    ExitProcess 1
    </code>

    Works fine. Only when i do NOT run the program from the IDE. Starting the program from the IDE runs the program from a thread in the process of the vb6.exe

    greetings,

    Dunebuggy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width