From: Trevor Smith on
I am using ShellExecuteEx to open up a Word form and then when the user
closes the document I examine the form and retrieve data from some of
the fields to put into a database. This works well except when the user
has Outlook running at the same time and then the program doesn't wait
for Word to finish and drops straight through to the UpdateCheck routine.

Is there any way to prevent this other than getting the user to close
Outlook?

The code goes like this:

// open the doc in Word
lpShellInfo.cbSize := _SizeOf( _winShellExecuteInfo )
lpShellInfo.hwnd := self:Handle()
lpShellInfo.lpVerb := String2Psz("open")
lpShellInfo.lpFile := String2Psz( cFile )
lpShellInfo.nShow := SW_ShowNormal
lpShellInfo.fMask := SEE_MASK_NOCLOSEPROCESS

if ShellExecuteEx( @lpShellInfo )
hProc := lpShellInfo.hProcess
GetExitCodeProcess( hProc, @lpExitCode )
lRunning := ( lpExitCode == STILL_ACTIVE )
while lRunning
GetExitCodeProcess( hProc, @lpExitCode )
lRunning := ( lpExitCode == STILL_ACTIVE )
Yield()
end

// see if the user wants to retrieve any fields from the // saved doc
oUC := UpdateCheck{self}
oUC:File := cFile
oUC:Show()
end

Thanks
Trevor
From: dlzc on
Dear Trevor Smith:

On Feb 6, 5:11 am, Trevor Smith <t®evs.mailbox(a)googlemail.©om> wrote:
....
> Is there any way to prevent this other than getting the
> user to close Outlook?

Could you write a routine that uses (the VO equivalent) of fopen() /
fclose() in exclusive mode, to see if you can have access to the file
yet? Just poll it at return from Word, say each second for
max_seconds, until you successfully get exclusive access to the file.

David A. Smith

From: John Martens on
Trevor,

Couln't you check with your own routine AND check until data-time of the
file has been chenged ?
Probably the date-time of the file will only change if the user closes
the doc.

John


Trevor Smith schreef:
> I am using ShellExecuteEx to open up a Word form and then when the user
> closes the document I examine the form and retrieve data from some of
> the fields to put into a database. This works well except when the user
> has Outlook running at the same time and then the program doesn't wait
> for Word to finish and drops straight through to the UpdateCheck routine.
>
> Is there any way to prevent this other than getting the user to close
> Outlook?
>
> The code goes like this:
>
> // open the doc in Word
> lpShellInfo.cbSize := _SizeOf( _winShellExecuteInfo )
> lpShellInfo.hwnd := self:Handle()
> lpShellInfo.lpVerb := String2Psz("open")
> lpShellInfo.lpFile := String2Psz( cFile )
> lpShellInfo.nShow := SW_ShowNormal
> lpShellInfo.fMask := SEE_MASK_NOCLOSEPROCESS
>
> if ShellExecuteEx( @lpShellInfo )
> hProc := lpShellInfo.hProcess
> GetExitCodeProcess( hProc, @lpExitCode )
> lRunning := ( lpExitCode == STILL_ACTIVE )
> while lRunning
> GetExitCodeProcess( hProc, @lpExitCode )
> lRunning := ( lpExitCode == STILL_ACTIVE )
> Yield()
> end
>
> // see if the user wants to retrieve any fields from the
> // saved doc
> oUC := UpdateCheck{self}
> oUC:File := cFile
> oUC:Show()
> end
>
> Thanks
> Trevor
From: G Schaller on
Trevor,

This won't help you directly but what you are doing is always going to
cause problems because of the existing instance of Word on the machine.
There is benefit to these kinds of processes to use the XML version of
MS Office 2003 or use MS Office 2007. Here you can open your word doc
without having to load or run MS Word itself. Because the doc is in XML
format you can now read data directly from fields using an XML parser or
just simply text parse the doc.

We have server processes which construct word docs on the server where
MS Office is not installed (think websites also). This is great for
standard letters and so on. I know this doesn't help this situation but
for those thinking of implementing this kind of technology, it bears
value thinking along these lines.

Geoff


"Trevor Smith" <t.evs.mailbox(a)googlemail.)om> wrote in message
news:eq9r86$5bv$1(a)news.datemas.de:

> I am using ShellExecuteEx to open up a Word form and then when the user
> closes the document I examine the form and retrieve data from some of
> the fields to put into a database. This works well except when the user
> has Outlook running at the same time and then the program doesn't wait
> for Word to finish and drops straight through to the UpdateCheck routine.
>
> Is there any way to prevent this other than getting the user to close
> Outlook?
>
> The code goes like this:
>
> // open the doc in Word
> lpShellInfo.cbSize := _SizeOf( _winShellExecuteInfo )
> lpShellInfo.hwnd := self:Handle()
> lpShellInfo.lpVerb := String2Psz("open")
> lpShellInfo.lpFile := String2Psz( cFile )
> lpShellInfo.nShow := SW_ShowNormal
> lpShellInfo.fMask := SEE_MASK_NOCLOSEPROCESS
>
> if ShellExecuteEx( @lpShellInfo )
> hProc := lpShellInfo.hProcess
> GetExitCodeProcess( hProc, @lpExitCode )
> lRunning := ( lpExitCode == STILL_ACTIVE )
> while lRunning
> GetExitCodeProcess( hProc, @lpExitCode )
> lRunning := ( lpExitCode == STILL_ACTIVE )
> Yield()
> end
>
> // see if the user wants to retrieve any fields from the // saved doc
> oUC := UpdateCheck{self}
> oUC:File := cFile
> oUC:Show()
> end
>
> Thanks
> Trevor

From: Gary Stark on
Trevor

Trevor Smith wrote:
> I am using ShellExecuteEx to open up a Word form and then when the user
> closes the document I examine the form and retrieve data from some of
> the fields to put into a database. This works well except when the user
> has Outlook running at the same time and then the program doesn't wait
> for Word to finish and drops straight through to the UpdateCheck routine.

If I'm understanding you correctly, then your application isn't actually
finding the Word application's Window, or else it thinks that Word has
finished before that actually is the case.

This sounds to me as if you're not getting the correct process handle,
or that Outbreak is somehow interrupting the process flow and forcing
you to be given the incorrect handle.

Have you examined the values that you're being returned when Outbreak is
also running? I'd start by examining that aspect, and try to understand
why you're unable to correctly monitor the process.

When you have a handle on what's happening to your handles, you can then
handle the problem in your own handler. :)





>
> Is there any way to prevent this other than getting the user to close
> Outlook?
>
> The code goes like this:
>
> // open the doc in Word
> lpShellInfo.cbSize := _SizeOf( _winShellExecuteInfo )
> lpShellInfo.hwnd := self:Handle()
> lpShellInfo.lpVerb := String2Psz("open")
> lpShellInfo.lpFile := String2Psz( cFile )
> lpShellInfo.nShow := SW_ShowNormal
> lpShellInfo.fMask := SEE_MASK_NOCLOSEPROCESS
>
> if ShellExecuteEx( @lpShellInfo )
> hProc := lpShellInfo.hProcess
> GetExitCodeProcess( hProc, @lpExitCode )
> lRunning := ( lpExitCode == STILL_ACTIVE )
> while lRunning
> GetExitCodeProcess( hProc, @lpExitCode )
> lRunning := ( lpExitCode == STILL_ACTIVE )
> Yield()
> end
>
> // see if the user wants to retrieve any fields from the
> // saved doc
> oUC := UpdateCheck{self}
> oUC:File := cFile
> oUC:Show()
> end
>
> Thanks
> Trevor