Tech Support > Microsoft Windows > Development Resources > CreateProcess and Console Application
CreateProcess and Console Application
Posted by Robin on September 22nd, 2004


Hello all,

I've created a Compaq Visual Fortran 6.1 Console App that gets
information from a SQL database using an ADO module created by the
Fortran Module Wizard. It works great and we're very happy.

Unfortunately, when this console app is called from a Visual Basic 6
program using the CreateProcess function, it can't open the ADO
connection or recordset. I get error number -2147352567 in my
connection_open statement in Fortran. The app creates the connection
object just fine.

Does anyone know what the difference is between calling this app from
CreateProcess and running it as an EXE? I suspect its in the way
CreateProcess is used, so I've attached my VB code below:


Dim lHndl As Long 'program handle
Dim udtProcInfo As PROCESS_INFORMATION 'process information
for EXE
Dim udtStart As STARTUPINFO 'startup info for EXE
Dim udtSecurity As SECURITY_ATTRIBUTES 'security attributes
for process
' and thread of EXE
Dim lInputEnd As Long 'position of the end of the input
data
Dim lFileHndl As Long 'handle to error file
Dim lExit As Long 'termination status of EXE

' open a file to catch errors
RtlZeroMemory udtSecurity, Len(udtSecurity)
udtSecurity.nLength = Len(udtSecurity)
udtSecurity.bInheritHandle = True
lFileHndl = CreateFile(sTempPath & sErrFile, FILE_WRITE_DATA, 0, _
udtSecurity, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, ByVal 0&)

' Initialize the STARTUPINFO structure:
RtlZeroMemory udtStart, Len(udtStart)
udtStart.cb = Len(udtStart)
udtStart.dwFlags = STARTF_USESHOWWINDOW + STARTF_USESTDHANDLES
udtStart.wShowWindow = SW_HIDE
udtStart.hStdOutput = lFileHndl
udtStart.hStdError = lFileHndl

' Clear and re-Initialize the security attributes
RtlZeroMemory udtSecurity, Len(udtSecurity)
udtSecurity.nLength = Len(udtSecurity)
udtSecurity.bInheritHandle = True

' Start the shelled application:
lRet = CreateProcess(vbNullString, sEXEPath & sProgName & ".EXE",
_
udtSecurity, udtSecurity, True, CREATE_NEW_CONSOLE +
NORMAL_PRIORITY_CLASS, _
0, vbNullString, _
udtStart, udtProcInfo)

' Wait for the shelled application to finish:
lRet = WaitForSingleObject(udtProcInfo.hProcess, 15000)
If lRet = WAIT_TIMEOUT Then
MsgBox "Program Abend - 15 second timeout limit exceeded. " &
_
"Please reduce the number of data sets or contact CAE.",
iMsgBox
lRet = CloseHandle(lHndl)
lHndl = OpenProcess(PROCESS_TERMINATE, 0, lShell)
If lHndl = 0 Then Exit Sub
lRet = TerminateProcess(lHndl, 0)
ElseIf lRet = WAIT_FAILED Then
MsgBox "Error Calling Program EXE - #" & Err.LastDllError & _
". Please contact CAE.", iMsgBox
GoTo RunProgErr
Else
'check normal/abnormal termination
lRet = GetExitCodeProcess(udtProcInfo.hProcess, lExit)
If lExit <> 0 Then _
MsgBox "An error occurred while attempting to run " &
sProgName & _
" . Please examine your input data for errors.", iMsgBox
End If
lRet = CloseHandle(lHndl)
lRet = CloseHandle(lFileHndl)

As always, many thanks in advance,
Robin

Posted by Michael Bruschkewitz on October 1st, 2004


In article <b1cee833.0409221127.6402451b@posting.google.com>,
msrado@yahoo.com says...

It is probably better to ask which error caused the FORTRAN-error number
-2147352567.
What happens if you don't use STARTF_USESTDHANDLES?

In a similar situation, I had to use DuplicateHandle/CloseHandle in the
parent process and pass the duplicated handle to the child. I don't
bother why.

Regards,
Michael B.

Posted by Robin on October 4th, 2004


Hi Michael,

I'm using STARTF_USESTDHANDLES so that I can collect any on-screen
error messages from the console app in an error file. So I think I
need that flag to get unexpected errors. I'll try using the
DuplicateHandle suggestion, though - I'm desperate enough.

Since my original post, I've discovered that CreateProcess has trouble
working with programs that call ADO. Others have experienced the
(-2147352567) error number under similar circumstances. So I may have
bumped into a Microsoft issue.

Thanks,
Robin

Michael Bruschkewitz <brusch2@gmx.net> wrote in message news:<MPG.1bc79f0e1849607f9896a4@news.compuserve.d e>...

Posted by Robin on October 5th, 2004


Hello all,

I figured it out. It was just a matter of setting the lpDesktop part
of the STARTUP_INFO structure to an empty string (""). Windows was
able to create an acceptable environment for ADO.

It's always the simplest things that take you the longest to debug
......

Robin

Posted by Michael Bruschkewitz on October 7th, 2004


In article <b1cee833.0410041859.3751fa7b@posting.google.com>,
msrado@yahoo.com says...
Did you use ZeroMemory for the STARTUP_INFO structure for
Initialization? Then it's only necessary to set the values for the
structure members which are used.

Ciao,
Michael B.

Posted by Gerry Thomas on October 7th, 2004



"Michael Bruschkewitz"
<brusch_removetheunderlinesandthetextbetween_4@gmx .net> wrote in message
news:MPG.1bcf206ba5b11b619896ac@news.compuserve.de ...
Good point: lp is a long pointer, integer(4).

ZeroMemory is good to do in Fortran and isn't necessary in VB which does it
for you.

--
You're Welcome,
Gerry T.
______
"Some of those writing letters to this program are slightly fictitious but
others definitely are not." -- Dick Cavett, host of The Detroit Symphony
Orchestra, PBS Radio.