Home All Groups Group Topic Archive Search About

Return an error code/message from a VB6 app

Author
21 Oct 2005 12:26 AM
Bill Baker
Is there a way to return an error code and/or description from a VB6 app at
runtime? In other words, if I run a VB6 executable called "VB1.exe" from
another VB6 executable called "VB2.exe", can "VB2.exe" obtain an error
level/exit code from "VB1.exe"?

Thanks,
--
Bill Baker

Author
21 Oct 2005 1:13 AM
Bob Butler
"Bill Baker" <BillBa***@discussions.microsoft.com> wrote in message
news:24B19CBE-9AF2-4B9D-A312-D2D72A058A11@microsoft.com
> Is there a way to return an error code and/or description from a VB6
> app at runtime? In other words, if I run a VB6 executable called
> "VB1.exe" from another VB6 executable called "VB2.exe", can "VB2.exe"
> obtain an error level/exit code from "VB1.exe"?

If you make VB1 and ActiveX EXE then VB2 can create an instance and you can
exchange any amount of data you want.

If it's a standard EXE then you can use the ExitProcess API call to return
an exit code from VB1.  You have to be very careful to do all possible
cleanup first since it is an abrupt termination and you shouldn't call it at
design time since it will exit the VB IDE without saving anything.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
21 Oct 2005 6:05 PM
Bill Baker
Thanks for the reply.

I converted my app to an ActiveX Exe app, and added a public AutoLogin
subroutine. I then referenced the executable in my main Exe project, and
attempted to make an instance:

Dim objAutoLogin As AutoLogin_App
Dim objAutoLogin As New AutoLogin_App

When I type "objAutoLogin.", intellisense doesn't show anything.

Am I not referencing this correctly? Do I need to declare it like an API?

Thanks again,
--
Bill Baker


Show quoteHide quote
"Bob Butler" wrote:

> "Bill Baker" <BillBa***@discussions.microsoft.com> wrote in message
> news:24B19CBE-9AF2-4B9D-A312-D2D72A058A11@microsoft.com
> > Is there a way to return an error code and/or description from a VB6
> > app at runtime? In other words, if I run a VB6 executable called
> > "VB1.exe" from another VB6 executable called "VB2.exe", can "VB2.exe"
> > obtain an error level/exit code from "VB1.exe"?
>
> If you make VB1 and ActiveX EXE then VB2 can create an instance and you can
> exchange any amount of data you want.
>
> If it's a standard EXE then you can use the ExitProcess API call to return
> an exit code from VB1.  You have to be very careful to do all possible
> cleanup first since it is an abrupt termination and you shouldn't call it at
> design time since it will exit the VB IDE without saving anything.
>
> --
> Reply to the group so all can participate
> VB.Net: "Fool me once..."
>
>
Author
21 Oct 2005 6:20 PM
GrandNagel
Bill Baker wrote:
> Dim objAutoLogin As New AutoLogin_App

Set objAutoLogin = New AutoLogin_App

D.
Author
21 Oct 2005 6:43 PM
Karl E. Peterson
Bill Baker wrote:
> Thanks for the reply.
>
> I converted my app to an ActiveX Exe app, and added a public AutoLogin
> subroutine. I then referenced the executable in my main Exe project,
> and attempted to make an instance:
>
> Dim objAutoLogin As AutoLogin_App
> Dim objAutoLogin As New AutoLogin_App
>
> When I type "objAutoLogin.", intellisense doesn't show anything.
>
> Am I not referencing this correctly? Do I need to declare it like an
> API?

Public subroutines are not exposed by COM.  You'll want to expose a public class,
instead, and make this routine accessible from there.
--
Working Without a .NET?
http://classicvb.org/petition
Author
21 Oct 2005 7:05 PM
Someone
> When I type "objAutoLogin.", intellisense doesn't show anything.

You have to create a class and set it to Public. Your Dim statement will
look like this:

Dim objAutoLogin As AutoLogin_App.Class1
Set objAutoLogin = New AutoLogin_App.Class1


However, I don't recommend the ActiveX approach, unless it's really useful
in you situation. Read my posts here for why:

http://groups.google.com/group/microsoft.public.vb.enterprise/browse_thread/thread/ef7517c84c5dd330/9cdebfc249927c07

Another approach is using SendMessage to send data to the other App. You
could use WM_COPYDATA to do this, but it requires subclassing. Another
slightly different way is sending a message like WM_KEYDOWN to a hidden
window with unique caption. This way you don't have to subclass if what you
want to do is very simple. Example:

Public Const WM_KEYDOWN = &H100
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As
Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As
Long

Public Sub Main()
    Dim h As Long

    h = FindWindow("ThunderRT6FormDC", "Form10") ' In EXE mode
    If h <> 0 Then
        SendMessage h, WM_KEYDOWN, 123, 456
    End If
    h = FindWindow("ThunderFormDC", "Form10") ' In IDE mode
    If h <> 0 Then
        SendMessage h, WM_KEYDOWN, 123, 456
    End If

End Sub

Note about using SendMessage vs. PostMessage: If you use SendMessage, the
call will not return until Form_KeyDown finishes processing. If you have a
MsgBox there, the call will not return until the user clicks it and the
event procedure finishes. If you use PostMessage, the call returns
immediately. By the time your event procedure fires, the application may
have ended already.




Show quoteHide quote
"Bill Baker" <BillBa***@discussions.microsoft.com> wrote in message
news:706E7E06-DD9C-4D9B-AE6B-EE0838D04E75@microsoft.com...
> Thanks for the reply.
>
> I converted my app to an ActiveX Exe app, and added a public AutoLogin
> subroutine. I then referenced the executable in my main Exe project, and
> attempted to make an instance:
>
> Dim objAutoLogin As AutoLogin_App
> Dim objAutoLogin As New AutoLogin_App
>
> When I type "objAutoLogin.", intellisense doesn't show anything.
>
> Am I not referencing this correctly? Do I need to declare it like an API?
>
> Thanks again,
> --
> Bill Baker
>
>
> "Bob Butler" wrote:
>
>> "Bill Baker" <BillBa***@discussions.microsoft.com> wrote in message
>> news:24B19CBE-9AF2-4B9D-A312-D2D72A058A11@microsoft.com
>> > Is there a way to return an error code and/or description from a VB6
>> > app at runtime? In other words, if I run a VB6 executable called
>> > "VB1.exe" from another VB6 executable called "VB2.exe", can "VB2.exe"
>> > obtain an error level/exit code from "VB1.exe"?
>>
>> If you make VB1 and ActiveX EXE then VB2 can create an instance and you
>> can
>> exchange any amount of data you want.
>>
>> If it's a standard EXE then you can use the ExitProcess API call to
>> return
>> an exit code from VB1.  You have to be very careful to do all possible
>> cleanup first since it is an abrupt termination and you shouldn't call it
>> at
>> design time since it will exit the VB IDE without saving anything.
>>
>> --
>> Reply to the group so all can participate
>> VB.Net: "Fool me once..."
>>
>>
Author
21 Oct 2005 6:53 PM
Bill Baker
In the meantime I'm using the ExecCmd example for running apps and getting a
return exit code, This uses the ExitProcess API:

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

Unfortunately, when I run my app, it always returns 1:

  lngRet = ExecCmd("C:\My Projects\AutoLogin.exe", 0)

My AutoLogin app has error trapping enabled (On Error Resume Next). I added
a failure by deleting a file that doesn't exist. With this, if I manually run
my AutoLogin app: Err.Number = 53. However running my AutoLogin app using
ExecCmd still reports exit code 1.

Thanks
--
Bill Baker


Show quoteHide quote
"Bob Butler" wrote:

> "Bill Baker" <BillBa***@discussions.microsoft.com> wrote in message
> news:24B19CBE-9AF2-4B9D-A312-D2D72A058A11@microsoft.com
> > Is there a way to return an error code and/or description from a VB6
> > app at runtime? In other words, if I run a VB6 executable called
> > "VB1.exe" from another VB6 executable called "VB2.exe", can "VB2.exe"
> > obtain an error level/exit code from "VB1.exe"?
>
> If you make VB1 and ActiveX EXE then VB2 can create an instance and you can
> exchange any amount of data you want.
>
> If it's a standard EXE then you can use the ExitProcess API call to return
> an exit code from VB1.  You have to be very careful to do all possible
> cleanup first since it is an abrupt termination and you shouldn't call it at
> design time since it will exit the VB IDE without saving anything.
>
> --
> Reply to the group so all can participate
> VB.Net: "Fool me once..."
>
>
Author
21 Oct 2005 8:30 PM
Bill Baker
Got it. Using ExitProcess in my AutoLogin app to return Err.Number.

Thanks everyone for the help.

--
Bill Baker


Show quoteHide quote
"Bill Baker" wrote:

> In the meantime I'm using the ExecCmd example for running apps and getting a
> return exit code, This uses the ExitProcess API:
>
>   http://support.microsoft.com/kb/q129796/
>
> Unfortunately, when I run my app, it always returns 1:
>
>   lngRet = ExecCmd("C:\My Projects\AutoLogin.exe", 0)
>
> My AutoLogin app has error trapping enabled (On Error Resume Next). I added
> a failure by deleting a file that doesn't exist. With this, if I manually run
> my AutoLogin app: Err.Number = 53. However running my AutoLogin app using
> ExecCmd still reports exit code 1.
>
> Thanks
> --
> Bill Baker
>
>
> "Bob Butler" wrote:
>
> > "Bill Baker" <BillBa***@discussions.microsoft.com> wrote in message
> > news:24B19CBE-9AF2-4B9D-A312-D2D72A058A11@microsoft.com
> > > Is there a way to return an error code and/or description from a VB6
> > > app at runtime? In other words, if I run a VB6 executable called
> > > "VB1.exe" from another VB6 executable called "VB2.exe", can "VB2.exe"
> > > obtain an error level/exit code from "VB1.exe"?
> >
> > If you make VB1 and ActiveX EXE then VB2 can create an instance and you can
> > exchange any amount of data you want.
> >
> > If it's a standard EXE then you can use the ExitProcess API call to return
> > an exit code from VB1.  You have to be very careful to do all possible
> > cleanup first since it is an abrupt termination and you shouldn't call it at
> > design time since it will exit the VB IDE without saving anything.
> >
> > --
> > Reply to the group so all can participate
> > VB.Net: "Fool me once..."
> >
> >
Author
21 Oct 2005 9:00 PM
Someone
> Got it. Using ExitProcess in my AutoLogin app to return Err.Number.

You may want to read this:

PRB: Call to ExitProcess() from Visual Basic Application Hinders Process
Exit
http://support.microsoft.com/default.aspx?scid=kb;en-us;288216




Show quoteHide quote
"Bill Baker" <BillBa***@discussions.microsoft.com> wrote in message
news:50320BB9-B5D9-47FD-AD3D-FBA59F12308D@microsoft.com...
> Got it. Using ExitProcess in my AutoLogin app to return Err.Number.
>
> Thanks everyone for the help.
>
> --
> Bill Baker
>
>
> "Bill Baker" wrote:
>
>> In the meantime I'm using the ExecCmd example for running apps and
>> getting a
>> return exit code, This uses the ExitProcess API:
>>
>>   http://support.microsoft.com/kb/q129796/
>>
>> Unfortunately, when I run my app, it always returns 1:
>>
>>   lngRet = ExecCmd("C:\My Projects\AutoLogin.exe", 0)
>>
>> My AutoLogin app has error trapping enabled (On Error Resume Next). I
>> added
>> a failure by deleting a file that doesn't exist. With this, if I manually
>> run
>> my AutoLogin app: Err.Number = 53. However running my AutoLogin app using
>> ExecCmd still reports exit code 1.
>>
>> Thanks
>> --
>> Bill Baker
>>
>>
>> "Bob Butler" wrote:
>>
>> > "Bill Baker" <BillBa***@discussions.microsoft.com> wrote in message
>> > news:24B19CBE-9AF2-4B9D-A312-D2D72A058A11@microsoft.com
>> > > Is there a way to return an error code and/or description from a VB6
>> > > app at runtime? In other words, if I run a VB6 executable called
>> > > "VB1.exe" from another VB6 executable called "VB2.exe", can "VB2.exe"
>> > > obtain an error level/exit code from "VB1.exe"?
>> >
>> > If you make VB1 and ActiveX EXE then VB2 can create an instance and you
>> > can
>> > exchange any amount of data you want.
>> >
>> > If it's a standard EXE then you can use the ExitProcess API call to
>> > return
>> > an exit code from VB1.  You have to be very careful to do all possible
>> > cleanup first since it is an abrupt termination and you shouldn't call
>> > it at
>> > design time since it will exit the VB IDE without saving anything.
>> >
>> > --
>> > Reply to the group so all can participate
>> > VB.Net: "Fool me once..."
>> >
>> >
Author
21 Oct 2005 9:09 PM
Karl E. Peterson
Someone wrote:
>> Got it. Using ExitProcess in my AutoLogin app to return Err.Number.
>
> You may want to read this:
>
> PRB: Call to ExitProcess() from Visual Basic Application Hinders
> Process Exit
> http://support.microsoft.com/default.aspx?scid=kb;en-us;288216

Bah!  That's cause they didn't read my column. <g>

  Ask the VB Pro, March 2001  (2nd Q)
  http://vb.mvps.org/articles/ap200103.asp

Later...   Karl
--
Working Without a .NET?
http://classicvb.org/petition