LoadCode

Loads a binary image into memory, and obtains a handle to it.

Synopsis

Err LoadCode(char *fileName, CodeHandle *code);

Description

This function loads an executable file from disk into memory. Once loaded, the code can be spawned as a thread, or executed as a subroutine.

In order to work correctly with this and associated functions, the executable file being loaded must have been linked with threadstartup.o or subroutinestartup.o instead of the usual cstartup.o.

Give this function the name of the executable file to load, as well as a pointer to a CodeHandle variable, where the handle for the loaded code will be stored. Note, "code" must point to a valid CodeHandle variable; that's where LoadCode() will put a pointer to the loaded code.

Once you finish using the loaded code, you can remove it from memory by passing the code handle to the UnloadCode() function.

To execute the loaded code, you must call either the ExecuteAsThread() function or the ExecuteAsSubroutine()function. Note that if the loaded code is reentrant, the same loaded code can be spawned multiple times simultaneously as a thread.

Arguments

fileName
A NULL-terminated string indicating the executable file to load.
code
A pointer to a CodeHandle variable, where a handle to the loaded code can be put.

Return Value

Returns > = 0 if successful, or a negative error code it the file could not be loaded.

Implementation

Folio call implemented in file folio V21.

Associated Files

filefunctions.h

See Also

LoadProgram(), UnloadCode(), ExecuteAsThread(), ExecuteAsSubroutine()