I use ShellExecute to execute IE opens some CGI script like:

HINSTANCE result = ShellExecute(NULL, _T("open"), mUrl, NULL,NULL, cmdshow );

Is it true?
And when I created, the handle is result?
And how to close this dialog by coding in my program?
Another way to run CGI script?


Please help me! thank you very much!
Posted on 2001-11-26 08:43:13 by bung
Use ShellExecuteEx instead, this function returns a handle to the newly created process, you can then use this handle to help you terminate the process, and do various other things with it.

Check out this for info on this function.
Posted on 2001-11-26 21:48:31 by sluggy
Here is an example in VB...
Public Type SHELLEXECUTEINFO

cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
' Optional fields
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
Public Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Public Declare Function Sleep Lib "kernel32" (ByVal dwMicroSecs As Long) As Long
Public Declare Function ShellExecuteEx Lib "shell32.dll" Alias "ShellExecuteExA" (lpExecInfo As SHELLEXECUTEINFO) As Long

Sub odbc()
'
' odbc Macro
' Macro created 11/23/2000 by bNaza

docum = "odbc"

If ActiveDocument = (docum + ".doc") Then

direct = "c:\My Documents\asm\db\"
rcprog = "Rc.exe"
rcpara = " /v " + "rsrc.rc"
cvprog = "Cvtres.exe"
cvpara = " /machine:ix86 " + "rsrc.res"
mlprog = "ml.exe"
mlpara = " /c /coff " + docum + ".asm"
linkprog = "link.exe"
linkpara = " /SUBSYSTEM:WINDOWS /RELEASE /MERGE:.rdata=.text /SECTION:.text" + "," + "CEWR " + docum + ".obj"
linkparaRes = " /SUBSYSTEM:WINDOWS /RELEASE /MERGE:.rdata=.text /SECTION:.text" + "," + "CEWR " + docum + ".obj " + "rsrc.obj"


'Save Document as asm(txt) and as doc files
ChangeFileOpenDirectory (direct)
ActiveDocument.SaveAs filename:=(docum + ".asm"), FileFormat:=wdFormatDOSText _
, LockComments:=False, Password:="", AddToRecentFiles:=False, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
ActiveDocument.SaveAs filename:=(docum + ".doc"), FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False

'Searching recource file
Set fs = Application.FileSearch
With fs
.LookIn = direct
.filename = "rsrc.obj"
If .Execute > 0 Then GoTo LResource
.filename = "rsrc.rc"
If .Execute > 0 Then
'Compiling the recource file
If (CheckProcStatus(rcprog, direct, rcpara, "rsrc.res", "Recource Compiling Error")) = False Then End
'Starting Resource to Object Convertor
If (CheckProcStatus(cvprog, direct, cvpara, "rsrc.obj", "Recource To Object Converting Error")) = False Then End
LResource:
linkpara = linkparaRes
End If
End With

'Compiling the asm file
If (CheckProcStatus(mlprog, direct, mlpara, (docum + ".obj"), "Compiling Error")) = False Then End
'Linking the obj and res file
If (CheckProcStatus(linkprog, direct, linkpara, (docum + ".exe"), "Link Error")) = False Then End
'Runing the exe file
Call Shell((docum + ".exe"), 1)
End If
End Sub

Public Function CheckProcStatus(ByVal prog As String, ByVal directory As String, ByVal param As String, ByVal filename As String, ByVal mess As String) As Boolean
Dim shellex As SHELLEXECUTEINFO

CheckProcStatus = False 'by default->Return error
shellex.cbSize = 60
shellex.fMask = &H40 'Public Const SEE_MASK_NOCLOSEPROCESS = &H40
shellex.lpVerb = "open"
shellex.nShow = 1
shellex.lpFile = prog
shellex.lpParameters = param
On Error GoTo Error
Set fs = Application.FileSearch
With fs
.LookIn = directory
.filename = filename
If .Execute > 0 Then Kill .filename 'Delete file if exist

If ShellExecuteEx(shellex) = 0 Or shellex.hInstApp < 33 Then GoTo Error

Loop1: 'Loop
Sleep (500) 'Wait 0.5 second
M = GetExitCodeProcess(shellex.hProcess, N1) 'N1->status flag
If N1 = &H103 Then GoTo Loop1 '&H103=Still_Active (process is)

If .Execute > 0 Then 'Search new created file name
CheckProcStatus = True 'Return success
Else
Error:
L = MsgBox((mess + "!"), 0, "Fatal error!") 'Return error
End If
End With
End Function
Posted on 2001-11-27 18:23:57 by buliaNaza
I use ShellExecuteEx, but my handle always = 0x00000000.

and this function always return TRUE!

:stupid:
Posted on 2001-11-28 00:43:42 by bung
Originally posted by bung
and this function always return TRUE!


Hang on one moment.... you are complaining that it is failing, but not posting any details?

When it returns TRUE, what is the value in the hInstApp member of the SHELLEXECUTEINFO struct? Is it 32 or below? And what do you have contained in the hProcess member of the same struct? And when you complain that your handle is NULL, what handle are you talking about?
Posted on 2001-11-28 03:19:02 by sluggy