|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Return an error code/message from a VB6 appIs 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 "Bill Baker" <BillBa***@discussions.microsoft.com> wrote in message If you make VB1 and ActiveX EXE then VB2 can create an instance and you cannews: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"? 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..." 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, -- Show quoteHide quoteBill 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..." > > Bill Baker wrote:
> Dim objAutoLogin As New AutoLogin_App Set objAutoLogin = New AutoLogin_AppD. Bill Baker wrote:
> Thanks for the reply. Public subroutines are not exposed by COM. You'll want to expose a public class,> > 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? instead, and make this routine accessible from there. > 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..." >> >> 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 -- Show quoteHide quoteBill 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..." > > Got it. Using ExitProcess in my AutoLogin app to return Err.Number.
Thanks everyone for the help. -- Show quoteHide quoteBill 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..." > > > > > 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..." >> > >> > Someone wrote:
>> Got it. Using ExitProcess in my AutoLogin app to return Err.Number. Bah! That's cause they didn't read my column. <g>> > 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 Ask the VB Pro, March 2001 (2nd Q) http://vb.mvps.org/articles/ap200103.asp Later... Karl |
|||||||||||||||||||||||