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

Call a CODE resource from another CODE resource


Appeler une ressource code d'une autre ressource code
I'm trying to call a precompiled code resource from a ENTER/EXIT PROC but it's not working.

I get a Big Crash + OSErr of type 1 (no need to restart)

SG


I had the same problem. What I figured out (with the help of Staz) is that the string 4 char code that identifies the resource type in the FB "CALL" routine doesn't work properly inside a code resource.

The only way I know of to call a code resource from inside another code resource is via assembly language.

Typical way to call a code resource in FB:

CALL "DCod",resID,err,glbls&, selector&, resData&

When calling a code resource from inside another code resource you need to do it this way...

LOCAL MODE
LOCAL FN CallMyDCod(resRefNum%, glbls&, selector&, resData&)
  curResFile% = FN CURRESFILE
  CALL USERESFILE(resRefNum%)
  drvrResHndl& = FN GET1INDRESOURCE(_"DCod",1)
  LONG IF drvrResHndl&
    LONG IF resRefNum% = FN HOMERESFILE(drvrResHndl&)
' first lock down the resource
      hState = FN HGETSTATE(drvrResHndl&)
      osErr = FN HLOCK(drvrResHndl&)
      resPtr& = [drvrResHndl&]
      ` CLR.W -(A7)
      ` MOVE.L ^glbls&,-(A7)
      ` MOVE.L ^selector&,-(A7)
      ` MOVE.L ^resData&,-(A7)
      ` MOVEA.L ^resPtr&, A0
      ` JSR (A0)
      ` MOVE.W (A7)+,^err
' unlock the resource after use
      osErr = FN HSETSTATE(drvrResHndl&, hState)
    END IF
  END IF
  CALL USERESFILE(curResFile%)
END FN = err

In my example above, I had a bunch of code resources that are drivers for external hardware and each is in a separate file, so I opened all the files when the main program was launched and saved the resource reference numbers for each of the driver files in globals so I was sure I was accessing the right code resource for each specific task.

Bill Sanford