How to Open Macintosh QuickBASIC Data File with Shared Access (58177)






This article was previously published under Q58177

SUMMARY

Below is an example of how to open a data file with "shared" access from Microsoft QuickBASIC Version 1.00 for the Apple Macintosh.

MORE INFORMATION

This program will not work on machines with 64K ROMs (pre-MacPlus).

WARNING: Because this routine temporarily changes the operating system, incorrect use can cause the system to crash or other adverse effects to occur. You should not make any major alterations to the code and should be very careful in its use.

Code Example

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'>> The following code demonstrates a technique for opening a
'>> file with shared access. It accomplishes this by patching
'>> the _OPEN OS routine to force the ioPermssn to Shared.
'>> WARNING - This is not a trivial technique. If a BASIC error
'>> occurs while the _OPEN trap is patched, the machine MUST
'>> be rebooted. Therefore, you should keep the code between the
'>> patch & unpatch to a minimum.
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    DIM reg&(16),hpatch&, pPatch&, pOpen&
    GetTrapAddress%=&HA246 : SetTrapAddress%=&HA247
    ToolBox "i"
'=== Find out where the current _OPEN code is
    ToolBox "RQ",GetTrapAddress%,reg&(0),0,0,0
    pOpen&=reg&(0)
'==== Set up the patch
    NewHandle 12,hpatch&
    hLock hpatch& : pPatch&=PEEKL(hpatch&)
    PRINT HEX$(PEEKL(hpatch&))
    POKEW pPatch&,&H117C        'Move.B #4,1B(a0)
    POKEW pPatch&+2,&H4         'immediate data
    POKEW pPatch&+4,&H1B        'reg offset
    POKEW pPatch&+6,&H4EF9      'jmp    OldOpenCode
    POKEL pPatch&+8,pOpen&      'Abs.L for jmp

'>>>>>>>>>>>>>>>>>>>> Start of Critical Section <<<<<<<<<<<<<<<<<
'==== Install the patch for _OPEN
    ToolBox "RQ",SetTrapAddress%,reg&(0),(pPatch&),0,0
'=== Opens a file with shared access. It must be opened with the
'=== patch.
'    OPEN "Am.tmp2" FOR INPUT AS 1

'==== Remove the patch
    ToolBox "RQ",SetTrapAddress%,reg&(0),(pOpen&),0,0
'>>>>>>>>>>>>>>>>>>>> End of Critical Section <<<<<<<<<<<<<<<<<<<

'==== clean up
    hunLock hpatch&
    DisposeHandle hpatch&
				

Modification Type: Minor Last Reviewed: 1/9/2003
Keywords: KB58177