For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > August 2005 > How to return process exitcode from VB6 application?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to return process exitcode from VB6 application?
Koji Shimazaki

2005-08-30, 3:55 am

I know VB.NET can return exitcode as follows, but I don't know how to do that
with VB6.

Function Main() As Integer
Return 1
End Function

I can set exitcode by ExitProcess(), but KB:288216 says don't do that.

Any ideas?

Thanks,

M. Posseth

2005-08-30, 3:55 am

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()
ExitProcess GetExitCodeProcess(GetCurrentProcess, 0)
End Sub

see : http://support.microsoft.com/kb/q129796/

well i do not see any text that you should not use it , i only see the
statement that
there are better ways to perform the same ( even with example )

regards

M.Posseth

"Koji Shimazaki" wrote:

> I know VB.NET can return exitcode as follows, but I don't know how to do that
> with VB6.
>
> Function Main() As Integer
> Return 1
> End Function
>
> I can set exitcode by ExitProcess(), but KB:288216 says don't do that.
>
> Any ideas?
>
> Thanks,
>

Tom Esh

2005-08-30, 7:55 am

On Mon, 29 Aug 2005 23:43:35 -0700, "Koji Shimazaki"
<KojiShimazaki@discussions.microsoft.com> wrote:

>I know VB.NET can return exitcode as follows, but I don't know how to do that
>with VB6.
>
> Function Main() As Integer
> Return 1
> End Function
>
>I can set exitcode by ExitProcess(), but KB:288216 says don't do that.


It's certainly possible to use ExitProcess successfully, but take care
to unload all forms and set all obj refs =nothing before calling it.
Also I'd recommend only calling it from a native-code compiled exe as
it may crash the IDE or the VB RT otherwise. Save often :-)

I'd use a routine like this to avoid calling it when running the app
in the IDE.


Public Function IsIDE() As Boolean
Debug.Assert Not TestIDE(IsIDE)
End Function
Private Function TestIDE(Test As Boolean) As Boolean
Test = True
End Function

'ex usage...
If Not IsIDE Then
ExitProcess somevalue
End If


-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com