FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

RESOURCES

Share resources between applications


I am writing a shared application but I am having troble with a few resources not showing up when more than 1 machine access the same program part.

oldres = FN CURRESFILE
RFnum% = FN HOPENRESFILE(SYSTEM(_aplVol), 0, res$, _fsRdWrPerm)
LONG IF RFnum% <> -1
CALL USERESFILE(RFnum%)
END IF
lh& = FN GETRESOURCE(_"PICT",1128)
PICTURE(0,0),lh&
CALL RELEASERESOURCE(lh&)
CALL USERESFILE(oldres)


In the absence of a network, I couldn't actually try out a shared application, and instead compiled multiple applications from the same source code, and allowed them to compete for the resource -- not quite the same thing :-(

The root cause is likely to be found in the permissions for HOPENRESFILE.
You were using _fsRdWrPerm. The file can then be opened by only 1 application; a second hopeful application fails with RESERR -49 (a.k.a. opWrErr) because the res file is open with write permission by the first.

One obvious solution would be to CALL CLOSERESFILE(RFnum%) after the pict is drawn and the resource released. But out of curiosity I experimented with different permissions. Either _fsRdWrShPerm or _fsRdPerm allows multiple applications to gain access to the resource file for reading.

Note that I have assumed in the following that res$ is the name of a separate file containing the PICT. Possibly (you don't say) res$ is actually the name of application itself.

This modified version of your code is protected against most errors, and prints diagnostics that may be useful for solving your problem:
COMPILE _dimmedvarsOnly
DIM res$,oldResFile,thisResFile,resHandle&,err

WINDOW 1
res$="myPictFile"   ' file with PICT 1128, in same folder as application
oldResFile=FN CURRESFILE
thisResFile=FN HOPENRESFILE(SYSTEM(_aplVol),0,res$,_fsRdWrShPerm)'_fsRdPerm
LONG IF thisResFile <> -1  ' no error from HOPENRESFILE
  CALL USERESFILE(thisResFile)
  resHandle&=FN GETRESOURCE(_"PICT",1128)
  LONG IF resHandle&       ' got resource handle
    PICTURE(0,0), resHandle&
    CALL RELEASERESOURCE(resHandle&)
  XELSE
    PRINT "Error in GETRESOURCE"
  END IF
  CALL USERESFILE(oldResFile)
XELSE
  err= FN RESERROR
  PRINT "Error " err" in HOPENRESFILE"
END IF

DO: HANDLEEVENTS: UNTIL 0
Robert