G
Gustav Bergquist
Hi,
I'm developing a PocketPC-application which needs to launch and get the
exitcode(Errorlevel) of a thirdparty application.
Now the problem is that I can't get the api-declaration right or maybe I'm
reading the results wrong... please help.
My guess is that lpExitCode in the API-declaration is bogus... because lp
stands for Long Pointer, shouldn't declaration then use IntPtr?
And second, how do I access the value which the pointer points to? I know
how to do this i C# but not VB.NET...
---API declarations---
<DllImport("coredll.dll")> Function CreateProcess(ByVal imageName As String,
ByVal cmdLine As String, ByVal lpProcessAttributes As IntPtr, ByVal
lpThreadAttributes As IntPtr, ByVal boolInheritHandles As Int32, ByVal
dwCreationFlags As Int32, ByVal lpEnvironment As IntPtr, ByVal lpCurrentDir
As IntPtr, ByVal si() As Byte, ByVal pi As ProcessInfo) As Int32
End Function
<DllImport("coredll.dll")> Function GetExitCodeProcess(ByVal hProcess As
Int32, ByVal lpExitCode As Int32) As Int32
End Function
<DllImport("coredll.dll")> Function TerminateProcess(ByVal hProcess As
Int32, ByVal iExitCode As Int32) As Boolean
End Function
<DllImport("coredll.dll")> Sub Sleep(ByVal iMilliseconds As Int32)
End Sub
<DllImport("coredll.dll")> Function WaitForSingleObject(ByVal hHandle As
Int32, ByVal dwMilliseconds As Int32) As Int32
End Function
---END API-declarations---
---CODE---
Dim STILL_ACTIVE As Int32
Dim si(128) As Byte
Dim pi As New ProcessInfo
Dim iRetVal As Int32
Dim iRet2Val As Int32
iRetVal = 0
STILL_ACTIVE = &H103
iRetVal = CreateProcess("thirdparty.exe", "", IntPtr.Zero, IntPtr.Zero, 0,
0, IntPtr.Zero, IntPtr.Zero, si, pi)
If iRetVal <> 0 Then
WaitForSingleObject(pi.hProcess, 10000)
iRetVal = GetExitCodeProcess(pi.hProcess, iRet2Val)
If iRetVal = 0 Then MsgBox("Error calling GetExitCodeProcess")
Do While iRet2Val = STILL_ACTIVE
Sleep(1000)
GetExitCodeProcess(pi.hProcess, iRet2Val)
Loop
MsgBox("Errorlevel: " & iRet2Val)
---END CODE---
Thanks for your input!
/Gustav Bergquist
I'm developing a PocketPC-application which needs to launch and get the
exitcode(Errorlevel) of a thirdparty application.
Now the problem is that I can't get the api-declaration right or maybe I'm
reading the results wrong... please help.
My guess is that lpExitCode in the API-declaration is bogus... because lp
stands for Long Pointer, shouldn't declaration then use IntPtr?
And second, how do I access the value which the pointer points to? I know
how to do this i C# but not VB.NET...
---API declarations---
<DllImport("coredll.dll")> Function CreateProcess(ByVal imageName As String,
ByVal cmdLine As String, ByVal lpProcessAttributes As IntPtr, ByVal
lpThreadAttributes As IntPtr, ByVal boolInheritHandles As Int32, ByVal
dwCreationFlags As Int32, ByVal lpEnvironment As IntPtr, ByVal lpCurrentDir
As IntPtr, ByVal si() As Byte, ByVal pi As ProcessInfo) As Int32
End Function
<DllImport("coredll.dll")> Function GetExitCodeProcess(ByVal hProcess As
Int32, ByVal lpExitCode As Int32) As Int32
End Function
<DllImport("coredll.dll")> Function TerminateProcess(ByVal hProcess As
Int32, ByVal iExitCode As Int32) As Boolean
End Function
<DllImport("coredll.dll")> Sub Sleep(ByVal iMilliseconds As Int32)
End Sub
<DllImport("coredll.dll")> Function WaitForSingleObject(ByVal hHandle As
Int32, ByVal dwMilliseconds As Int32) As Int32
End Function
---END API-declarations---
---CODE---
Dim STILL_ACTIVE As Int32
Dim si(128) As Byte
Dim pi As New ProcessInfo
Dim iRetVal As Int32
Dim iRet2Val As Int32
iRetVal = 0
STILL_ACTIVE = &H103
iRetVal = CreateProcess("thirdparty.exe", "", IntPtr.Zero, IntPtr.Zero, 0,
0, IntPtr.Zero, IntPtr.Zero, si, pi)
If iRetVal <> 0 Then
WaitForSingleObject(pi.hProcess, 10000)
iRetVal = GetExitCodeProcess(pi.hProcess, iRet2Val)
If iRetVal = 0 Then MsgBox("Error calling GetExitCodeProcess")
Do While iRet2Val = STILL_ACTIVE
Sleep(1000)
GetExitCodeProcess(pi.hProcess, iRet2Val)
Loop
MsgBox("Errorlevel: " & iRet2Val)
---END CODE---
Thanks for your input!
/Gustav Bergquist