|
-
July 19th, 2001, 03:28 AM
#1
eMbedded VB
Hi,
I am working on a application development on Windows CE. I am using eMbedded Visual Basic. I have encountered a problem. I want to launch another application from my eMbedded VB application. "Shell" function does not work in eMbedded VB. Can any one help me in this regard?
Thanks in advance
-
July 19th, 2001, 11:50 AM
#2
Re: eMbedded VB
You have to use the CreateProcess API.
In a module:
option Explicit
public Declare Function TerminateProcess Lib "Coredll" (byval hProcess as Long, byval uExitCode as Long) as Long
public Declare Function CreateProcess Lib "coredll.DLL" _
Alias "CreateProcessW" _
(byval lpApplicationName as string, _
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, _
byval lpStartupInfo as Long, _
byval lpProcessInformation as string) as Long
public Function MemStringToLong(StringIn as string) as Long
on error resume next
Dim hWorkVal as string
'
' Convert the string back to Long Integer.
' Converting back to Big Endian format.
Dim i as Long
for i = 4 to 1 step -1
hWorkVal = hWorkVal & Hex(AscB(MidB(StringIn, i, 1)))
next i
'
' Return Long Integer value.
MemStringToLong = CLng("&H" & hWorkVal)
End Function
public Sub getPROCESS_INFORMATION(byval sPROCESS_INFORMATION as string, _
byref hProcess as Long, byref hThread as Long, _
byref dwProcessId as Long, byref dwThreadId as Long)
'
' Convert memory-formatted string back to Long Integer.
hProcess = MemStringToLong(MidB(sPROCESS_INFORMATION, 1, 4))
hThread = MemStringToLong(MidB(sPROCESS_INFORMATION, 5, 4))
dwProcessId = MemStringToLong(MidB(sPROCESS_INFORMATION, 9, 4))
dwThreadId = MemStringToLong(MidB(sPROCESS_INFORMATION, 13, 4))
End Sub
public Function LongToMemoryString(byval lInputValue as Long) as string
Dim hWorkVal as string
Dim n as Long
Dim i as Long
'
' Convert to HEX value.
hWorkVal = Hex(lInputValue)
'
' Check to see if it is not zero.
If hWorkVal <> "0" then
'
' Convert to memory storage format (Little Endian).
' for example, 0000A411 would convert to 11A40000.
'
' Place leading zeros in 8 character sequence to
' maintain consistent character count
n = len(hWorkVal)
If n < 8 then
hWorkVal = string(8 - n, "0") & hWorkVal
End If
'
' Use ChrB to rebuild Bytes.
for i = 7 to 1 step -2
LongToMemoryString = LongToMemoryString & _
ChrB(CInt("&H" & mid(hWorkVal, i, 2)))
next i
else
' Just return zeros.
' Use ChrB to build Bytes.
LongToMemoryString = ChrB(CInt("&H00"))
LongToMemoryString = LongToMemoryString & ChrB(CInt("&H00"))
LongToMemoryString = LongToMemoryString & ChrB(CInt("&H00"))
LongToMemoryString = LongToMemoryString & ChrB(CInt("&H00"))
End If
End Function
public Function PROCESS_INFORMATION(hProcess as Long, hThread as Long, _
dwProcessId as Long, dwThreadId as Long) as string
'
' Convert inbound Long Integers to a memory storage string format.
PROCESS_INFORMATION = LongToMemoryString(hProcess) & _
LongToMemoryString(hThread) & _
LongToMemoryString(dwProcessId) & _
LongToMemoryString(dwThreadId)
End Function
In your form put two labels(label1 & label2), two text boxes(text1 & text2), and one command button(command1).
option Explicit
private Sub Command1_Click()
Dim lRet as Long
Dim sPROCESS_INFORMATION as string
Dim hProcess as Long
Dim hThread as Long
Dim dwProcessId as Long
Dim dwThreadId as Long
'
' Initialize PROCESS_INFORMATION memory string.
' Convert initial Rect values to string to pass into CreateProcess API.
sPROCESS_INFORMATION = PROCESS_INFORMATION(0, 0, _
0, 0)
'
' Call CreateProcess.
lRet = CreateProcess(CStr(Text1.Text), CStr(Text2.Text), _
0, 0, 0, 0, 0, 0, 0, sPROCESS_INFORMATION)
'
'convert string back to long integer
getPROCESS_INFORMATION sPROCESS_INFORMATION, hProcess, hThread, _
dwProcessId, dwThreadId
'
'The handle to the process is returned in the sPROCESS_INFORMATION
'string when CreateProcess is called. This hProcess value can
'be passed to TerminateProcess.
'Uncomment the 3 lines below to terminate the process.
'MsgBox "Click to terminate process"
'Dim x as Long
'x = TerminateProcess(hProcess, 0)
End Sub
private Sub Form_Load()
Command1.Move 240, 240, 2895, 615
Label1.Move 240, 960, 1935, 255
Label2.Move 240, 1680, 1935, 255
Text1.Move 240, 1320, 1935, 255
Text2.Move 240, 2040, 1935, 255
Command1.Caption = "Create Process"
Label1.Caption = "Path to executable:"
Label2.Caption = "Command line:"
Text1.Text = "\windows\iexplore.exe" 'Change to Whatever You Want
Text2.Text = "\my documents\stats.htm" 'Change to Whatever You Want
End Sub
private Sub Form_OKClick()
App.End
End Sub
I you want the source code send me a private message with your e-mail.
Kris
Software Engineer
Phoenix,AZ
Kris
Software Engineer
Phoenix, AZ USA
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|