[futurebasic] Re: Getting App's VRefNum% in FB's Mini Runtime

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 1997 : Group Archive : Group : All Groups

From: Rick Brown <rbrown@...>
Date: Thu, 20 Nov 1997 21:06:12 -0600
Bill Sanford wrote:
> 
> Does anyone know how to convert the following into something I can use
> with  the Mini Runtime package.
> 
> appVRefNum% = SYSTEM(_aplVol)

I would do it by first calling GetProcessInformation, which you can use
to get a bunch of information about the current process, including the
location of the process's application file.  That will tell you the
(true) volume reference number and directory ID where the app is
located: that's a little bit different from the information that
SYSTEM(_aplVol) returns, which is in the form of a working directory
reference number.  However, you can feed the volume reference number and
directory ID into FN OPENWD in order to generate a working directory
ref. num.  The following code is patched together from working app's,
though I haven't tested it in this exact form: hope it helps.

- Rick

_myProcessAppSpec = 56                            '(constant in FB
mis-defined)
_myProcessSignature = 20                          '(constant in FB
mis-defined)
DIM RECORD fsSpec
  DIM fsVRefNum%
  DIM fsParID&
  DIM 63 fsName$
DIM END RECORD .fsSpec
'-------------------------------------------------
LOCAL FN GetProcessInformation(@PSNptr&, infoPtr&)
  'Call as follows:
  'OSErr = FN GetProcessInformation(PSN, @infoRec)
  'PSN should be an 8-byte record, infoRec a 60-byte record.
  '
  'We'll automatically fill in the processInfoLength field,
  'which is not normally done by GetProcessInformation:
  infoPtr&.processInfoLength& = 60
  '
  `     CLR.W   -(SP)
  `     MOVE.L  ^PSNptr&,-(SP)
  `     MOVE.L  ^infoPtr&,-(SP)
  `     MOVE.W  #$003A,-(SP)
  `     DC.W    $A88F
  `     MOVE.W  (SP)+,^OSErr
END FN = OSErr
'-------------------------------------------------------
CLEAR LOCAL
DIM infoRec.60
DIM theProcess.8
DIM iopb.52
LOCAL FN ApplFolder
  'Returns a working directory ref. number for the folder
  'containing the current application file.
  theProcess.highLongOfPSN& = 0
  theProcess.lowLongOfPSN& = _kCurrentProcess
  OSErr = FN GetProcessInformation(theProcess, @infoRec)
  LONG IF OSErr
    '[Handle error]
  XELSE
    appSpec& = infoRec.myProcessAppSpec&
    iopb.ioCompletion& = _nil
    iopb.ioNamePtr& = _nil
    iopb.ioVRefNum% = appSpec&.fsVRefNum%
    iopb.ioWDDirID& = appSpec&.fsParID&
    iopb.ioWDProcID& = infoRec.myProcessSignature&'(per I.M.
recommendation)
    OSErr = FN OPENWD(@iopb)
    LONG IF OSErr
      '[Handle error]
    END IF
  END IF
END FN = iopb.ioVRefNum%
'-------------------------------------------------------