[futurebasic] Re: [FB] Launching applications

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2002 : Group Archive : Group : All Groups

From: "Steven J. Stratford" <sstrat@...>
Date: Sun, 06 Jan 2002 14:10:22 -0600
> David Cottrell asked:
> 
> A quick search of the archive reveals a  number of different ways to
> sublaunch and external application from within an FB application, but
> all the examples I have found require that you know the location of the
> external application (eg FB's RUN command)
> 
> However, a number of applications I have seen let you launch an
> application without there being any way that they could know where I
> have hidden it on my HD.
> 
> Does anyone know how they do it?

This is how I do it. Someone helped me with it a couple of years ago. The
little demo will launch SimpleText. Just change the creator code near the
bottom to launch a different application. Sorry I don't remember where I got
the nicely documented functions, [someone speak up if they're yours]. I
think it might work with FB2 also. It might be limited to launching an
application only if it's on the same volume.

'------begin FB^3 program-------
begin RECORD procSerNumRec
DIM psnHigh&
DIM psnLow&
END RECORD '.procSerNumRec

begin RECORD myProcessInfoRec
DIM processInfoLength&'unsigned long
DIM processName&'StringPtr
DIM processNum as procSerNumRec'ProcessSerialNumber
DIM processType&'unsigned long
DIM processSignature&'unsigned long
DIM processMode&'unsigned long
DIM processLocation&'pointer
DIM processSize&'unsigned long
DIM processFreeMem&'unsigned long
DIM processLauncher as procSerNumRec'ProcessSerialNumber
DIM processLaunchDate&'unsigned long
DIM processActiveTime&'unsigned long
DIM processAppSpec&'FSSpecPtr
END RECORD '.processInfoRec

begin record ParamBlockHeader
dim qLink&
dim qType%
dim ioTrap%
dim ioCmdAddr&
dim ioCompletion&
dim ioResult%
dim ioNamePtr&
dim ioVRefNum%
end record'24

begin RECORD DTPBRec
dim pb as ParamBlockHeader
dim ioDTRefNum%
dim ioIndex%
dim ioTagInfo&
dim ioDTBuffer&
dim ioDTReqCount&
dim ioDTActCount&
dim dummy1.4
dim ioDirID&
dim ioFileCreator&
dim ioFileType&
dim dummy2.4
dim ioDTLgLen&
dim ioDTPyLen&
dim dummy3.28
dim ioAPPLParID&
END RECORD '104

_kBootVol       = -1
toolbox fn PBDTGetPath(LONG) = WORD`0x205F,0x7020,0xA260,0x3E80
toolbox fn PBDTGetAPPLSync(LONG) = WORD`0x205F,0x7027,0xA260,0x3E80


'****************************************************
'*
'*   FUNCTION FindApp(gAppSig : longint) : Boolean;
'*
'*      FN FindApp(gAppSig&)
'*
'*      Searches processes looking for the signature
'*      of the server for this application's Apple events.
'*
'*      Local variables:
'*              thePSN : procSerNumRec - process serial number RECORD
'*              theProcessInfo : - process information record
'*
'*      On entry:
'*              Server's application signature
'*
'*      On exit:
'*              boolean : _ztrue if process found, else _false
'***************************************************
clear LOCAL MODE
LOCAL FN FindApp(gAppSig&)'Do it!
DIM thePSN as ProcessSerialNumber'Process serial number record
DIM theProcessInfo as myProcessInfoRec'Process info block
DIM result%, OSErr%
theProcessInfo.processInfoLength& = 60'length of ProcessInfoRec
theProcessInfo.processName& = _nil'No name
theProcessInfo.processAppSpec& = _nil'No app specification
thePSN.highLongOfPSN&             = _nil'Zero-out high order
thePSN.lowLongOfPSN&              = _kNoProcess'Start with first process
result% = _false'Assume no good
WHILE FN GetNextProcess(thePSN) <> _procNotFound'Find a process, any process
OSErr% = FN GetProcessInformation(thePSN,theProcessInfo)'Get info on process
LONG IF OSErr% = _noErr'No error if ok
LONG IF theProcessInfo.processSignature& = gAppSig&'Our application?
result% = _ztrue  : goto "FINDAPP_END"'Yep, so set result true and split
END IF'   IF gAppSig&
END IF'  IF OSErr
WEND' WHILE <> _procNotFound
"FINDAPP_END"
END FN = result%'of FN FindApp

'**************************************************************
'*
'*      FUNCTION SearchDTDB(gAppSig&:Longint): boolean;
'*
'*      LOCAL FN SearchDTDB(gAppSig&)
'*
'*      Given a server's application signature, will first
'*      scan active processes, and if the target application
'*      is not running, will then check the Finder's desktop
'*      database for the thing. If it can find the app in the
'*      database, it will launch it if possible.
'*      Returns _ztrue if file found and launched, _false if not.
'*
'*      NOTE: This routine can ONLY be used on a device with a
'*      capacity greater than 2 MB.
'*
'*      Local variables:
'*                theDataBase:DTDBRec - desktop DB param block
'*                theFSSpec:FSSpec - File specification record for target
'*                theLPB:LaunchParameterBlock - extended launch parameter
block
'*                result% : integer - result of searches
'*                OSErr : integer - buffer for OS error
'*
'*      On entry:
'*               gAppSig& : OSType (long) - Server's application signature
'*
'*      On exit:
'*              result% (word) _ztrue if file found and launched,
'*                             else _false.
'***********************************************************************

clear LOCAL MODE
LOCAL FN SearchDTDB(gAppSig&)
DIM theDB as DTPBRec
DIM theLPB as LaunchParamBlockRec
DIM theFSSpec as FSSpec
DIM result%,tmp%'result of search
DIM OSErr%'buffer for error
theDB.pb.ioCompletion& = _nil'no completion
theDB.pb.ioNamePtr&    = _nil'Don't care yet
theDB.pb.ioVRefNum%    = _kBootVol'Boot volume only
OSErr% = FN PBDTGetPath(@theDB)'Is anyone out there?
LONG IF OSErr%
'fn ToDebugWnd(0,"Got an error after FN PBDTGetPath in FN
SearchDTDB)--desktop DB not found",_zTrue)
XELSE
LONG IF OSErr% = _noErr'Have a DT DB?
_ioFileCreator = 52'Offset for pBlock
_ioAPPLParID   = 100'Offset for pBlock
theDB.ioIndex%     = 0'Most recent creation date
theDB.ioFileCreator& = gAppSig&'The target's signature
theDB.pb.ioNamePtr&     = @theFSSpec.Name'Call puts name here
OSErr% = FN PBDTGetAPPLSync(@theDB)'Find application itself
LONG IF OSErr%
'fn ToDebugWnd(0,"You need MondoMail for this CGI
(www.acmetech.com)",_zTrue)
XELSE
LONG IF OSErr% = _noErr'Ok?
theFSSpec.VRefNum%        = theDB.pb.ioVRefNum%'We need volume ref number
theFSSpec.ParID&          = theDB.ioAPPLParID&
theLPB.launchBlockID%       = _extendedBlock'Use extended block
theLPB.launchEPBLength%     = _extendedBlockLen'Length of extended block
theLPB.launchControlFlags%  =
_launchContinue_launchNoFileFlags_launchUseMinimum_launchDontSwitch
theLPB.launchFileFlags% = 0
theLPB.launchAppSpec&       = @theFSSpec'The road-map to the server
theLPB.launchAppParameters& = 0'Just launch...
OSErr% = FN LaunchApplication(@theLPB)
LONG IF OSErr%
'fn ToDebugWnd(0,"Error launching Mondomail: "+str$(OSErr%),_zTrue)
END IF' of IF OSErr
END IF'  IF OSErr = _noErr
END IF
END IF
END IF
END FN = OSErr%'of  FN SearchDTDB

dim theText$
dim OSErr%
dim @appSig&
appSig& = _"ttxt"
OSErr% = FN FindApp(appSig&)'Look for application
LONG IF not OSErr%
OSErr% = FN SearchDTDB(appSig&)'Not running, so try to launch
LONG IF OSErr%
theText$ = "Error: App not launched"
END IF
END IF

'------end FB^3 program-------


--Steve

_____________________________
Steven J. Stratford, InterNetyx.com
http://www.internetyx.com
Web Site hosting services
CGI shareware for Mac/WebStar servers
Custom CGI programming
_____________________________