Top DevX Stories
Top 6 Tips for Agile Testing
Adobe Buys Day Software to Bolster ECM Portfolio
Useful UML Modeling: Two of a Kind
Programming, Development Skills in Demand
Cloud Working Group Developing Standard APIs
Search the forums:

Go Back   DevX.com Forums > DevX Developer Forums > VB Classic

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 12-08-2000, 10:47 AM
Guy
Guest
 
Posts: n/a
shell and wait


Hi,

From my VB6 exe, I want to call another program and wait for it to return
before continuing. I am having (at least) two problems with this, they may
be related.

1) When I use the shell command to call the other program, it leaves a DOS
command window open, but I need it to close on its own. Here's my command
syntax:

RetVal = Shell("mypgm.bat arg1 arg2")

2) I have seen in some resources that I can use the code (down below) to
solve the "shell and wait" problem, but I cannot get it to compile. I put
the two function declarations in the general declarations section following
the variables and contants and get this compile error message:

"Constants, fixed length strings, arrays, user-defined types and declare
statements not allowed as public members of object modules."

Any help would be appreciated...Guy

And here's the code...
Declare Function OpenProcess Lib "kernel32" Alias "OpenProcess" (ByVal dwDesiredAccess
As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject
As Long) As Long

Private Sub ShellAndWait(ByVal strProg as String, ByVal lStyle As VbAppWinStyle)
Dim ProcessId As Long
Dim ProcessHandle As Long
Const Access As Long = &H100000
ProcessId = Shell(strProg, lStyle)
Do
ProcessHandle = OpenProcess(Access, False, ProcessId)
If ProcessHandle <> 0 Then
CloseHandle ProcessHandle
End If
DoEvents
Loop Until ProcessHandle = 0
End Sub

Reply With Quote
  #2  
Old 12-08-2000, 12:04 PM
Guy
Guest
 
Posts: n/a
Re: shell and wait


I managed to find the answers for this one. In case you have the same problem
(gee, they seem so simple once they're solved), the solutions are embedded
below...Guy

"Guy" <ghokanson@diamonddata.com> wrote:
>
>Hi,
>
>From my VB6 exe, I want to call another program and wait for it to return
>before continuing. I am having (at least) two problems with this, they may
>be related.
>
>1) When I use the shell command to call the other program, it leaves a DOS
>command window open, but I need it to close on its own. Here's my command
>syntax:
>
> RetVal = Shell("mypgm.bat arg1 arg2")


Solution: (courtesy of http://support.microsoft.com/support.../Q138/8/07.asp

Start the program using the MS-DOS command interpreter, Command.com, with
the /C switch. This switch closes the window after the program quits. For
example, to run a batch file, use the following command:
Shell "command.com /c fred.bat"


>
>2) I have seen in some resources that I can use the code (down below) to
>solve the "shell and wait" problem, but I cannot get it to compile. I put
>the two function declarations in the general declarations section following
>the variables and contants and get this compile error message:
>
>"Constants, fixed length strings, arrays, user-defined types and declare
>statements not allowed as public members of object modules."
>


Solution: courtesy of
http://msdn.microsoft.com/library/de...lprocedure.htm

DLL procedures declared in standard modules are public by default and can
be called from anywhere in your application. DLL procedures declared in any
other type of module are private to that module, and you must identify them
as such by preceding the declaration with the Private keyword.

(I merely had to precede the declarations with "Private")


>Any help would be appreciated...Guy
>
>And here's the code...
>Declare Function OpenProcess Lib "kernel32" Alias "OpenProcess" (ByVal dwDesiredAccess
>As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
>Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject
>As Long) As Long
>
>Private Sub ShellAndWait(ByVal strProg as String, ByVal lStyle As VbAppWinStyle)
> Dim ProcessId As Long
> Dim ProcessHandle As Long
> Const Access As Long = &H100000
> ProcessId = Shell(strProg, lStyle)
> Do
> ProcessHandle = OpenProcess(Access, False, ProcessId)
> If ProcessHandle <> 0 Then
> CloseHandle ProcessHandle
> End If
> DoEvents
> Loop Until ProcessHandle = 0
>End Sub
>


Reply With Quote
  #3  
Old 12-08-2000, 12:04 PM
Guy
Guest
 
Posts: n/a
Re: shell and wait


I managed to find the answers for this one. In case you have the same problem
(gee, they seem so simple once they're solved), the solutions are embedded
below...Guy

"Guy" <ghokanson@diamonddata.com> wrote:
>
>Hi,
>
>From my VB6 exe, I want to call another program and wait for it to return
>before continuing. I am having (at least) two problems with this, they may
>be related.
>
>1) When I use the shell command to call the other program, it leaves a DOS
>command window open, but I need it to close on its own. Here's my command
>syntax:
>
> RetVal = Shell("mypgm.bat arg1 arg2")


Solution: (courtesy of http://support.microsoft.com/support.../Q138/8/07.asp

Start the program using the MS-DOS command interpreter, Command.com, with
the /C switch. This switch closes the window after the program quits. For
example, to run a batch file, use the following command:
Shell "command.com /c fred.bat"


>
>2) I have seen in some resources that I can use the code (down below) to
>solve the "shell and wait" problem, but I cannot get it to compile. I put
>the two function declarations in the general declarations section following
>the variables and contants and get this compile error message:
>
>"Constants, fixed length strings, arrays, user-defined types and declare
>statements not allowed as public members of object modules."
>


Solution: courtesy of
http://msdn.microsoft.com/library/de...lprocedure.htm

DLL procedures declared in standard modules are public by default and can
be called from anywhere in your application. DLL procedures declared in any
other type of module are private to that module, and you must identify them
as such by preceding the declaration with the Private keyword.

(I merely had to precede the declarations with "Private")


>Any help would be appreciated...Guy
>
>And here's the code...
>Declare Function OpenProcess Lib "kernel32" Alias "OpenProcess" (ByVal dwDesiredAccess
>As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
>Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject
>As Long) As Long
>
>Private Sub ShellAndWait(ByVal strProg as String, ByVal lStyle As VbAppWinStyle)
> Dim ProcessId As Long
> Dim ProcessHandle As Long
> Const Access As Long = &H100000
> ProcessId = Shell(strProg, lStyle)
> Do
> ProcessHandle = OpenProcess(Access, False, ProcessId)
> If ProcessHandle <> 0 Then
> CloseHandle ProcessHandle
> End If
> DoEvents
> Loop Until ProcessHandle = 0
>End Sub
>


Reply With Quote
  #4  
Old 12-08-2000, 12:06 PM
michiel de bruijn
Guest
 
Posts: n/a
Re: shell and wait

Hi Guy,

> "Constants, fixed length strings, arrays, user-defined types and declare
> statements not allowed as public members of object modules."


Which is exactly your problem. Adding the Private keyword in front of each
Declare will solve it.

'//mdb


Reply With Quote
  #5  
Old 12-08-2000, 12:06 PM
michiel de bruijn
Guest
 
Posts: n/a
Re: shell and wait

Hi Guy,

> "Constants, fixed length strings, arrays, user-defined types and declare
> statements not allowed as public members of object modules."


Which is exactly your problem. Adding the Private keyword in front of each
Declare will solve it.

'//mdb


Reply With Quote
  #6  
Old 12-09-2000, 11:27 AM
Sergey Merzlikin
Guest
 
Posts: n/a
Re: shell and wait

Hello!
>
> Solution: (courtesy of

http://support.microsoft.com/support.../Q138/8/07.asp
>
> Start the program using the MS-DOS command interpreter, Command.com, with
> the /C switch. This switch closes the window after the program quits. For
> example, to run a batch file, use the following command:
> Shell "command.com /c fred.bat"
>


This solution depends on contents of command.pif file in Windows or
Windows\pif directory. Some users can have this file with very unusual
settings (for example "Run full-screen") . To be sure your bat-file or any
other DOS application would br launched with correct settings, always create
PIF file and shell it instead of bat or com or exe file.

Your ShellAndWait function is very time-consuming because it uses endless
cycle. Actually you need to call OpenProcess once and then to use one of API
wait functions.
See here to learn how to use wait functions in Visual Basic:
http://smsoft.chat.ru/en/vbwait.htm

Sergey Merzlikin
http://smsoft.chat.ru
smsoft@chat.ru



Reply With Quote
  #7  
Old 12-09-2000, 11:27 AM
Sergey Merzlikin
Guest
 
Posts: n/a
Re: shell and wait

Hello!
>
> Solution: (courtesy of

http://support.microsoft.com/support.../Q138/8/07.asp
>
> Start the program using the MS-DOS command interpreter, Command.com, with
> the /C switch. This switch closes the window after the program quits. For
> example, to run a batch file, use the following command:
> Shell "command.com /c fred.bat"
>


This solution depends on contents of command.pif file in Windows or
Windows\pif directory. Some users can have this file with very unusual
settings (for example "Run full-screen") . To be sure your bat-file or any
other DOS application would br launched with correct settings, always create
PIF file and shell it instead of bat or com or exe file.

Your ShellAndWait function is very time-consuming because it uses endless
cycle. Actually you need to call OpenProcess once and then to use one of API
wait functions.
See here to learn how to use wait functions in Visual Basic:
http://smsoft.chat.ru/en/vbwait.htm

Sergey Merzlikin
http://smsoft.chat.ru
smsoft@chat.ru



Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 01:13 PM.


Sponsored Links



Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.