Hello list,
Got a little Quiz for all MapBasic guru's out there, I
found VB-code (http://www.allapi.net/tips/tip5.php) to
see if an application executed via shell is running
yes or no. I tried to translate it to MapBasic, but it
keeps returning errors, where did I go wrong?
---------------ORIGINAL VB CODE---------------------
How do I tell when an application executed using the
SHELL command is finished?
It is often necessary for a program to know when a
shelled application has finished. We have procedure
that does not return control to the rest of the
program until the application that has been shelled is
quit. To use this procedure, simply call
ExecCmd(strProgram).
Declarations
This code must be placed in the declarations section
of the project.
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Declare Function WaitForSingleObject Lib _
"kernel32" (ByVal hHandle As Long, ByVal
dwMilliseconds _
As Long) As Long
Declare Function CreateProcessA Lib "kernel32" _
(ByVal lpApplicationName As Long, ByVal lpCommandLine
As _
String, ByVal lpProcessAttributes As Long, ByVal _
lpThreadAttributes As Long, ByVal bInheritHandles As
Long, _
ByVal dwCreationFlags As Long, ByVal lpEnvironment As
Long, _
ByVal lpCurrentDirectory As Long, lpStartupInfo As _
STARTUPINFO, lpProcessInformation As
PROCESS_INFORMATION) _
As Long
Declare Function CloseHandle Lib "kernel32" (ByVal
hObject _
As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Prodedure
This is the code that can be called to execute an
external program. Simply copy this code into the code
of your project. To run an external program, call
ExecCmd(program) from anywhere in your code.
Public Sub ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
' Initialize the STARTUPINFO structure:
start.cb = Len(start)
' Start the shelled application:
ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
ret& = CloseHandle(proc.hProcess)
End Sub
-----------MY MB code------------------------
'in the declarations section
Type STARTUPINFO
cb As Integer
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Integer
dwY As Integer
dwXSize As Integer
dwYSize As Integer
dwXCountChars As Integer
dwYCountChars As Integer
dwFillAttribute As Integer
dwFlags As Integer
wShowWindow As smallInt
cbReserved2 As smallInt
lpReserved2 As Integer
hStdInput As Integer
hStdOutput As Integer
hStdError As Integer
End Type
Type PROCESS_INFORMATION
hProcess As Integer
hThread As Integer
dwProcessID As Integer
dwThreadID As Integer
End Type
Declare Function WaitForSingleObject Lib "kernel32"
(ByVal hHandle As Integer, ByVal dwMilliseconds As
Integer) As Integer
Declare Function CreateProcessA Lib "kernel32" (ByVal
lpApplicationName As Integer, ByVal lpCommandLine As
String, ByVal lpProcessAttributes As Integer, ByVal
lpThreadAttributes As Integer, ByVal bInheritHandles
As Integer, ByVal dwCreationFlags As Integer, ByVal
lpEnvironment As Integer, ByVal lpCurrentDirectory As
Integer, lpStartupInfo As STARTUPINFO,
lpProcessInformation As PROCESS_INFORMATION) As
Integer
Declare Function CloseHandle Lib "kernel32" (ByVal
hObject As Integer) As Integer
Define NORMAL_PRIORITY_CLASS = &H20&
Define INFINITE = -1&
declare Sub ExecCmd(cmdline$ as string)
' as a little sub routine
Sub ExecCmd(cmdline$ as string)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret& as integer
' Initialize the STARTUPINFO structure:
start.cb = Len(start)
' Start the shelled application:
ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&,
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
ret& = CloseHandle(proc.hProcess)
End Sub
Good luck!
And the price is: First to e-mail me the working
solution will be sent a postcard from the Netherlands,
and is invited to visit whenever he or she is in the
Netherlands!
=====
Ing. M.F. (Milo) van der Linden
NetGIS
kvk. 30166407
ABN Amro 57.64.10.535
NL - 3437TT NIEUWEGEIN
+31(0)616598808
____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie
_______________________________________________________________________
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, send e-mail to [EMAIL PROTECTED] and
put "unsubscribe MapInfo-L" in the message body.