Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Tue Dec 12, 2017 6:47 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: wait for launch to complete
PostPosted: Wed Feb 27, 2013 12:14 pm 
Offline

Joined: Tue Jan 17, 2006 4:13 pm
Posts: 108
Location: Kilgore, TX
Is there a way for an RB application (or a thread of it) to wait for an f.Launch to complete?

This external application could put some data in the clipboard, depending on what the user does, and I want to check the clipboard for this data when the external application closes.


Top
 Profile  
Reply with quote  
 Post subject: Re: wait for launch to complete
PostPosted: Wed Feb 27, 2013 12:38 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
Look in the Examples folder in the RB install directory for the Windows Functionality Suite. In the WFS there's a function called LaunchAndWait that does exactly what it's name says.

Note that your entire application will stop running until LaunchAndWait is done waiting (i.e. the other app exits.)

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: wait for launch to complete
PostPosted: Wed Feb 27, 2013 1:27 pm 
Offline

Joined: Tue Jan 17, 2006 4:13 pm
Posts: 108
Location: Kilgore, TX
I'm looking in the following path:

C:\Program Files (x86)\Real Software\Real Studio 2012r2.1\Example Projects

I'm not seeing a Windows Functionality Suite.

I also saw the following path, but also did not find it there:

C:\Program Files (x86)\Real Software\Real Studio 2012r2.1\Example Projects\Platform-Specific\Windows


Top
 Profile  
Reply with quote  
 Post subject: Re: wait for launch to complete
PostPosted: Wed Feb 27, 2013 2:17 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
For me, it's here:
C:\Program Files (x86)\REAL Software\Real Studio 2011r4.3\Example Projects\Windows OS specific\Windows Functionality Suite 2.5.

Here's the function I'm talking about:

Sub LaunchAndWait(extends f as FolderItem, params as String = "", deskName as String = "")
// We want to launch the application and wait for
// it to finish executing before we return.
#if TargetWin32
Soft Declare Function CreateProcessW Lib "Kernel32" ( appName as WString, params as WString, _
procAttribs as Integer, threadAttribs as Integer, inheritHandles as Boolean, flags as Integer, _
env as Integer, curDir as Integer, startupInfo as Ptr, procInfo as Ptr ) as Boolean

Soft Declare Function CreateProcessA Lib "Kernel32" ( appName as CString, params as CString, _
procAttribs as Integer, threadAttribs as Integer, inheritHandles as Boolean, flags as Integer, _
env as Integer, curDir as Integer, startupInfo as Ptr, procInfo as Ptr ) as Boolean

dim startupInfo, procInfo as MemoryBlock

startupInfo = new MemoryBlock( 17 * 4 )
procInfo = new MemoryBlock( 16 )

dim unicodeSavvy as Boolean = System.IsFunctionAvailable( "CreateProcessW", "Kernel32" )

startupInfo.Long( 0 ) = startupInfo.Size

dim deskStr, deskPtr as MemoryBlock
if deskName <> "" then
if unicodeSavvy then
deskStr = ConvertEncoding( deskName + Chr( 0 ), Encodings.UTF16 )
else
deskStr = deskName + Chr( 0 )
end if

startupInfo.Ptr( 8 ) = deskStr
end if

dim ret as Boolean
if unicodeSavvy then
ret = CreateProcessW( f.AbsolutePath, params, 0, 0, false, 0, 0, 0, startupInfo, procInfo )
else
ret = CreateProcessA( f.AbsolutePath, params, 0, 0, false, 0, 0, 0, startupInfo, procInfo )
end if

if not ret then return

Declare Function WaitForSingleObject Lib "Kernel32" ( handle as Integer, howLong as Integer ) as Integer
Const INFINITE = -1
Const WAIT_TIMEOUT = &h00000102
Const WAIT_OBJECT_0 = &h0

// We want to loop here so that we can yield time back
// to other threads. This means threaded applications
// will "just work", but non-threaded ones will still appear hung.
while WaitForSingleObject( procInfo.Long( 0 ), 1 ) = WAIT_TIMEOUT
App.SleepCurrentThread( 10 )
wend

Declare Sub CloseHandle Lib "Kernel32" ( handle as Integer )
CloseHandle( procInfo.Long( 0 ) )
CloseHandle( procInfo.Long( 4 ) )
#endif
End Sub


Call it like this (e.g.):

Dim f As FolderItem = SpecialFolder.Desktop.Child("TestFile.exe")
f.LaunchAndWait()
'Or:
f.LaunchAndWait("--optional-command-line-params")

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: wait for launch to complete
PostPosted: Wed Feb 27, 2013 2:35 pm 
Offline

Joined: Tue Jan 17, 2006 4:13 pm
Posts: 108
Location: Kilgore, TX
Thanks. I went back and installed RB20114.3 - (must be discontinued) and found it in the place you specified. Thanks for the tip. I can see in the code that it should work if I call this from a thread as it will only "hang" that thread.

-Dan


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group