 |
|
|
|
| Author |
Message |
sid
Joined: 26 Feb 2008 Posts: 2
|
Posted: Tue Feb 26, 2008 4:53 pm Post subject: Call and vb6.exe and return values ? |
|
|
I need to write a VB6 executable and have it perform some routines,
but when its finished, I want it to return some values as to what it
found and problems that it encountered.
I have tried using the stdin and stdout from VB6 before, but it seems
that it has a problem and has not been resolved.
Any help is appreciated.
Archived from group: microsoft>public>vb>general>discussion |
|
| Back to top |
|
 |
Karl E. Peterson
Joined: 04 Oct 2007 Posts: 4836
|
Posted: Tue Feb 26, 2008 5:20 pm Post subject: Re: Call and vb6.exe and return values ? |
|
|
sid wrote:
>I need to write a VB6 executable and have it perform some routines,
> but when its finished, I want it to return some values as to what it
> found and problems that it encountered.
>
> I have tried using the stdin and stdout from VB6 before, but it seems
> that it has a problem and has not been resolved.
If you want to write a console app, please see http://vb.mvps.org/samples/Console
If by "values" you actually mean you want to return multiple values, I'm not sure
where stdin/stdout come into play. Perhaps you could explain further?
--
..NET: It's About Trust!
http://vfred.mvps.org |
|
| Back to top |
|
 |
Bob Riemersma
Joined: 27 Dec 2007 Posts: 54
|
Posted: Tue Feb 26, 2008 10:53 pm Post subject: Re: Call and vb6.exe and return values ? |
|
|
"Karl E. Peterson" wrote in message @TK2MSFTNGP05.phx.gbl...
> sid wrote:
>>I need to write a VB6 executable and have it perform some routines,
>> but when its finished, I want it to return some values as to what it
>> found and problems that it encountered.
>>
>> I have tried using the stdin and stdout from VB6 before, but it seems
>> that it has a problem and has not been resolved.
>
> If you want to write a console app, please see
> http://vb.mvps.org/samples/Console
>
> If by "values" you actually mean you want to return multiple values, I'm
> not sure where stdin/stdout come into play. Perhaps you could explain
> further?
> --
> .NET: It's About Trust!
> http://vfred.mvps.org
For simple cases you can use the FSO to get references to the StdIO streams
as TextStream objects. Look at the FSO method GetStandardStream():
http://msdn2.microsoft.com/en-us/library/y6hbz9es(VS.85).aspx
Of course as Karl's article suggests you'll need to produce an EXE properly
linked for the Console Subsystem. You can post-process your VB6 EXE using
either LINK.EXE or EDITBIN.EXE (just a wrapper on LINK.EXE) to set the
subsystem. I usually just keep a small drag/drop VBS on hand for this: drag
the compiled VB6 EXE to the script's icon and drop it. Add-ins of the type
Karl mentions work fine too though. |
|
| Back to top |
|
 |
Kevin Provance
Joined: 04 Oct 2007 Posts: 800
|
Posted: Tue Feb 26, 2008 11:21 pm Post subject: Re: Call and vb6.exe and return values ? |
|
|
Geez, I hate to keep disagreeing with you at every post, but the FSO is
*not* recommended for use in VB as described in a recent thread here. It
causes more problems than it solves.
If I read the OP correctly, I think he's asking of there is a way to set the
return value of his .EXE after it has ended, just as a concole app would. I
thought that I read someplace over the years there was a way to do this, but
I don't rightly recall where and if that was the case...it may have very
well been the console app I am remembering.
- Kev
"Bob Riemersma" wrote in message @comcast.com...
| "Karl E. Peterson" wrote in message
| @TK2MSFTNGP05.phx.gbl...
| > sid wrote:
| >>I need to write a VB6 executable and have it perform some routines,
| >> but when its finished, I want it to return some values as to what it
| >> found and problems that it encountered.
| >>
| >> I have tried using the stdin and stdout from VB6 before, but it seems
| >> that it has a problem and has not been resolved.
| >
| > If you want to write a console app, please see
| > http://vb.mvps.org/samples/Console
| >
| > If by "values" you actually mean you want to return multiple values, I'm
| > not sure where stdin/stdout come into play. Perhaps you could explain
| > further?
| > --
| > .NET: It's About Trust!
| > http://vfred.mvps.org
|
| For simple cases you can use the FSO to get references to the StdIO
streams
| as TextStream objects. Look at the FSO method GetStandardStream():
|
| http://msdn2.microsoft.com/en-us/library/y6hbz9es(VS.85).aspx
|
| Of course as Karl's article suggests you'll need to produce an EXE
properly
| linked for the Console Subsystem. You can post-process your VB6 EXE using
| either LINK.EXE or EDITBIN.EXE (just a wrapper on LINK.EXE) to set the
| subsystem. I usually just keep a small drag/drop VBS on hand for this:
drag
| the compiled VB6 EXE to the script's icon and drop it. Add-ins of the
type
| Karl mentions work fine too though.
| |
|
| Back to top |
|
 |
Karl E. Peterson
Joined: 04 Oct 2007 Posts: 4836
|
Posted: Tue Feb 26, 2008 8:44 pm Post subject: Re: Call and vb6.exe and return values ? |
|
|
Kevin Provance wrote:
> Geez, I hate to keep disagreeing with you at every post, but the FSO is
> *not* recommended for use in VB as described in a recent thread here. It
> causes more problems than it solves.
Agreed.
> If I read the OP correctly, I think he's asking of there is a way to set the
> return value of his .EXE after it has ended, just as a concole app would. I
> thought that I read someplace over the years there was a way to do this, but
> I don't rightly recall where and if that was the case...it may have very
> well been the console app I am remembering.
Pretty simple, really:
' Return appropriate exit code, but *only*
' if running from EXE, else IDE exits too.
' App *must* be compiled to native code to
' avoid a nasty shutdown GPF in runtime!
If Compiled Then
Call ExitProcess(nMsg.wParam)
End If
(from http://vb.mvps.org/samples/Hello - a VB recreation of Petzold's "Hello
Windows!" app.)
--
..NET: It's About Trust!
http://vfred.mvps.org |
|
| Back to top |
|
 |
Karl E. Peterson
Joined: 04 Oct 2007 Posts: 4836
|
Posted: Tue Feb 26, 2008 8:45 pm Post subject: Re: Call and vb6.exe and return values ? |
|
|
Bob Riemersma wrote:
> For simple cases you can use the FSO to get references to the StdIO streams
> as TextStream objects. Look at the FSO method GetStandardStream():
>
> http://msdn2.microsoft.com/en-us/library/y6hbz9es(VS.85).aspx
Wasn't aware that was even available. Prolly not a good idea in all but, as you
suggest, the simplest cases. But interesting to know about!
> Of course as Karl's article suggests you'll need to produce an EXE properly
> linked for the Console Subsystem. You can post-process your VB6 EXE using
> either LINK.EXE or EDITBIN.EXE (just a wrapper on LINK.EXE) to set the
> subsystem. I usually just keep a small drag/drop VBS on hand for this: drag
> the compiled VB6 EXE to the script's icon and drop it.
That actually sounds like a cool little script! Is it shared/shareable?
> Add-ins of the type Karl mentions work fine too though.
My favorite is now available free -- http://www.vbadvance.com
--
..NET: It's About Trust!
http://vfred.mvps.org |
|
| Back to top |
|
 |
Bob Butler
Joined: 04 Oct 2007 Posts: 1081
|
Posted: Tue Feb 26, 2008 8:50 pm Post subject: Re: Call and vb6.exe and return values ? |
|
|
"Karl E. Peterson" wrote in message @TK2MSFTNGP06.phx.gbl...
> Kevin Provance wrote:
>> If I read the OP correctly, I think he's asking of there is a way to set
>> the
>> return value of his .EXE after it has ended, just as a concole app would.
The OP said they wanted to return status valueS so I took it that a single
32-bit integer would nt be enough. If it is then ExitProcess may be enough.
>> I thought that I read someplace over the years there was a way to do
>> this, but
>> I don't rightly recall where and if that was the case...it may have very
>> well been the console app I am remembering.
>
> Pretty simple, really:
>
> ' Return appropriate exit code, but *only*
> ' if running from EXE, else IDE exits too.
> ' App *must* be compiled to native code to
> ' avoid a nasty shutdown GPF in runtime!
I've used it often from PCode and never had a problem so there must be
something else in combination that causes the problem.
> If Compiled Then
> Call ExitProcess(nMsg.wParam)
> End If
>
> (from http://vb.mvps.org/samples/Hello - a VB recreation of Petzold's
> "Hello Windows!" app.)
> --
> .NET: It's About Trust!
> http://vfred.mvps.org
> |
|
| Back to top |
|
 |
Karl E. Peterson
Joined: 04 Oct 2007 Posts: 4836
|
Posted: Tue Feb 26, 2008 9:05 pm Post subject: Re: Call and vb6.exe and return values ? |
|
|
Bob Butler wrote:
> "Karl E. Peterson" wrote in message
> @TK2MSFTNGP06.phx.gbl...
>> Kevin Provance wrote:
>>> If I read the OP correctly, I think he's asking of there is a way to set the
>>> return value of his .EXE after it has ended, just as a concole app would.
>
> The OP said they wanted to return status valueS so I took it that a single
> 32-bit integer would nt be enough. If it is then ExitProcess may be enough.
Yeah, I was hesitant to offer it, because of that wording myself. But the latter
reference to std i/o led me to think he was in fact talking about a console app.
Who knows? I asked for clarification.
>>> I thought that I read someplace over the years there was a way to do
>>> this, but
>>> I don't rightly recall where and if that was the case...it may have very
>>> well been the console app I am remembering.
>>
>> Pretty simple, really:
>>
>> ' Return appropriate exit code, but *only*
>> ' if running from EXE, else IDE exits too.
>> ' App *must* be compiled to native code to
>> ' avoid a nasty shutdown GPF in runtime!
>
> I've used it often from PCode and never had a problem so there must be
> something else in combination that causes the problem.
Could be it was just one (version of one?) of the runtimes that was doing it? I
definitely remember taking it right down to the simplest possible case, back when I
wrote that column.
Public Sub Main
Call ExitProcess(1)
End Sub
Pcode EXEs tossed a GPF in the runtime. No idea what SP we might've been at then?
Would've been Nov/Dec 2000ish.
You're right, though. I just tried it with VB5/SP3, and it's not doing it now.
Hmmmmm...
--
..NET: It's About Trust!
http://vfred.mvps.org |
|
| Back to top |
|
 |
Bob Butler
Joined: 04 Oct 2007 Posts: 1081
|
Posted: Tue Feb 26, 2008 9:28 pm Post subject: Re: Call and vb6.exe and return values ? |
|
|
"Karl E. Peterson" wrote in message
news:%23IPu7RNeIHA.6136@TK2MSFTNGP03.phx.gbl...
> You're right, though. I just tried it with VB5/SP3, and it's not doing it
> now. Hmmmmm...
It's funny the little things that get ingrained but no longer hold... I
still can't bring myself to write something like
Do Until x
because one version along the line changed the implicit meaning from
"xFalse" to "x=True" which caused some loops to behave differently. It
was patched quickly but once burned... |
|
| Back to top |
|
 |
Karl E. Peterson
Joined: 04 Oct 2007 Posts: 4836
|
Posted: Tue Feb 26, 2008 9:58 pm Post subject: Re: Call and vb6.exe and return values ? |
|
|
Bob Butler wrote:
> "Karl E. Peterson" wrote ...
>> You're right, though. I just tried it with VB5/SP3, and it's not doing it
>> now. Hmmmmm...
>
> It's funny the little things that get ingrained but no longer hold... I
> still can't bring myself to write something like
> Do Until x
> because one version along the line changed the implicit meaning from
> "xFalse" to "x=True" which caused some loops to behave differently. It
> was patched quickly but once burned...
Ouch! Yeah, same deal here. I still remember the night I got bit by this one, too.
Was up to 3am, on deadline, trying to find what it was. Finally, I stumbled upon
the pcode/native distinction! Well, as you say, "once burned..."
--
..NET: It's About Trust!
http://vfred.mvps.org |
|
| Back to top |
|
 |
Kevin Provance
Joined: 04 Oct 2007 Posts: 800
|
Posted: Wed Feb 27, 2008 2:32 am Post subject: Re: Call and vb6.exe and return values ? |
|
|
| That actually sounds like a cool little script! Is it shared/shareable?
Karl -
A quick Google turned this up: http://www.tek-tips.com/faqs.cfm?fid=5647
If it's not the one previously mentioned, then it's close to it.
- Kev |
|
| Back to top |
|
 |
sid
Joined: 26 Feb 2008 Posts: 2
|
Posted: Wed Feb 27, 2008 1:00 pm Post subject: Re: Call and vb6.exe and return values ? |
|
|
I was able to get what I needed from a shell.
oShell.Exec(....
Thanks |
|
| Back to top |
|
 |
Karl E. Peterson
Joined: 04 Oct 2007 Posts: 4836
|
Posted: Wed Feb 27, 2008 7:44 pm Post subject: Re: Call and vb6.exe and return values ? |
|
|
Kevin Provance wrote:
>| That actually sounds like a cool little script! Is it shared/shareable?
>
> Karl -
>
> A quick Google turned this up: http://www.tek-tips.com/faqs.cfm?fid=5647
>
> If it's not the one previously mentioned, then it's close to it.
Slick! It works, too. Always a bonus. For the archives, unaltered:
Option Explicit
'LinkConsole.vbs
'
'This is a WSH script used to make it easier to edit
'a compiled VB6 EXE using LINK.EXE to create a console
'mode program.
'
'Drag the EXE's icon onto the icon for this file, or
'execute it from a command prompt as in:
'
' LinkConsole.vbs
'
'Be sure to set up strLINK to match your VB installation.
Dim strLINK, strEXE, WSHShell
strLINK = """C:\Program Files\Microsoft Visual Studio\VB98\LINK.EXE"""
strEXE = """" & WScript.Arguments(0) & """"
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.Run _
strLINK & " /EDIT /SUBSYSTEM:CONSOLE " & strEXE
Set WSHShell = Nothing
WScript.Echo "Complete!"
Just needs updating for the hardcoded path to LINK.
Thanks...
--
..NET: It's About Trust!
http://vfred.mvps.org |
|
| Back to top |
|
 |
Bob Riemersma
Joined: 27 Dec 2007 Posts: 54
|
Posted: Wed Feb 27, 2008 11:08 pm Post subject: Re: Call and vb6.exe and return values ? |
|
|
Yes, that's my script. Short and sweet.
I usually just leave a copy in the project folder of anything I need it for.
"Karl E. Peterson" wrote in message @TK2MSFTNGP04.phx.gbl...
> Kevin Provance wrote:
>>| That actually sounds like a cool little script! Is it shared/shareable?
>>
>> Karl -
>>
>> A quick Google turned this up: http://www.tek-tips.com/faqs.cfm?fid=5647
>>
>> If it's not the one previously mentioned, then it's close to it.
>
> Slick! It works, too. Always a bonus. For the archives, unaltered:
>
> Option Explicit
> 'LinkConsole.vbs
> '
> 'This is a WSH script used to make it easier to edit
> 'a compiled VB6 EXE using LINK.EXE to create a console
> 'mode program.
> '
> 'Drag the EXE's icon onto the icon for this file, or
> 'execute it from a command prompt as in:
> '
> ' LinkConsole.vbs
> '
> 'Be sure to set up strLINK to match your VB installation.
>
> Dim strLINK, strEXE, WSHShell
>
> strLINK = """C:\Program Files\Microsoft Visual Studio\VB98\LINK.EXE"""
> strEXE = """" & WScript.Arguments(0) & """"
> Set WSHShell = CreateObject("WScript.Shell")
>
> WSHShell.Run _
> strLINK & " /EDIT /SUBSYSTEM:CONSOLE " & strEXE
>
> Set WSHShell = Nothing
> WScript.Echo "Complete!"
>
> Just needs updating for the hardcoded path to LINK.
>
> Thanks...
> --
> .NET: It's About Trust!
> http://vfred.mvps.org
> |
|
| Back to top |
|
 |
Karl E. Peterson
Joined: 04 Oct 2007 Posts: 4836
|
Posted: Wed Feb 27, 2008 8:19 pm Post subject: Re: Call and vb6.exe and return values ? |
|
|
Bob Riemersma wrote:
> Yes, that's my script. Short and sweet.
>
> I usually just leave a copy in the project folder of anything I need it for.
Did you author it?
I'd really like to include it, as an option, with the Console code I offer, if I
may?
Couldn't be simpler, if you don't already have an add-in doing it automatically.
Thanks... Karl
--
..NET: It's About Trust!
http://vfred.mvps.org
|
|
| Back to top |
|
 |
|
|
| Related Topics: | VB6, IF statement logic and function return values The problem that I am seeing is that some of my code is not running correctly. I'll try to explain. I have 3 IF statements, the second IF statement evaluates the return value of a function. For some reason the function always returns False, even though wh
Pass 2 values to a sub I need to pass 2 values to a sub procedure. Here is what I am testing with: sub Form_Load() "123 Main") end sub public sub TheAlert (ByVal TheName as string, ByVal TheStreet as string) msgbox TheName msgbox TheStreet end sub -------------
Formatting of Hex values Hi, I want to be able to print out the hex value of :0E:06 but instead i keep coming up with :E:06 what is the magic syntax here :(
Return act like TAB in textboxes? Hi, VB6 SP6, powered by a newbie on XP Pro: I have a series of text boxes; TAB works well for going to the next box to have the focus. I -think- I can convert Return to a Tab with something like: Dim KeyAscii As (variant type?) KeyAscii
Return a value to Windows Hi, I am using VB 6.0 to write an ActiveX.exe and my program should return value of 0 or 1 depending on the outcome. The host program that call my ActiveX.exe will have to parse my return value for further processing. Could anyone tells me how to pass a v |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|