AddCtResource

AddCtResource

Add a Resource to a data file.

Short Name

ADDRES()

Type

Low-Level file resource function

Declaration

COUNT AddCtResource(FILNO filno, pVOID resptr, VRLEN varlen)

Description

In V12, the file number typedef was formally changed from COUNT, a two-byte value to FILNO, a four-byte value. Refer to this link for compatibility details. Four Byte File Numbering TypeDef Change

AddCtResource() is used to add a Resource to filno. Every Resource is identified by a unique combination of a Resource Type and a Resource Number. The Resource Number can optionally be assigned by FairCom DB during the call to AddCtResource(). In addition, each Resource can be identified by a Resource Name. The Resource Name is not guaranteed to be unique.

resptr points to a resource data block. This block contains the following fields:

Byte Offset Data Type Field Name
0 - 3 unsigned long integer Resource Type
4 - 7 unsigned long integer Resource Number
8 - m null terminated character string Resource Name
m+1 - n any collection of data types desired Resource Information

The Resource Type must be a value greater than 65536. 0 through 65536 are reserved for FairCom use.

If the Resource Number is a value of 0xffffffffL, FairCom DB assigns this Resource the next available Resource Number for this Resource Type in the specified data file. AddCtResource() places assigned Resource Number in the Resource Data Block.

The Resource Name is optional. FairCom DB does not guarantee unique Resource Names. Names starting with “FC!” or “RD!”, are reserved for FairCom use.

The Resource Information is any collection of data that you wish to store as a Resource. It can be a character string, a structure, or any variable type.

Return

Value Symbolic Constant Explanation
0 NO_ERROR Successful addition of a new Resource.
37 WRITE_ERR Most likely disk or directory is full. Files are left in an indeterminate state and should be rebuilt
147 VDLFLG_ERR Attempt to re-use a data record that is still active. Apparently, the data file is corrupted in which case you should rebuild the file.
401 RNON_ERR Resources have not been enabled for this data file.
403 RZRO_ERR Empty Resource ID.
405 RDUP_ERR Resource ID already added. There must be a unique combination of Type and Number.

See FairCom DB Error Codes for a complete listing of valid FairCom DB error values.

Example

struct {                    /* Resource Data Block structure */

    ULONG     resource_type;

    ULONG     resource_number;

    TEXT      variable_info[1016]; /* This holds the         */

} my_resource;                     /* Resource Name and Data */


my_resource.resource_type    = 0x10001L;            /* 65537 */

my_resource.resource_number  = 0xffffffffL;         /* FairCom DB assigns number*/


strcpy(my_resource.variable_info,"MY!resource");

strcpy(my_resource.variable_info+12,"Actual Resource Data");


if (AddCtResource(datno,&my_resource,

   (VRLEN)(8 + 12 + strlen(my_resource.variable_info+12))) == 0)

{

    printf("\nThe resource has been assigned number %ld",

           my_resource.resource_number);

    printf("\nThe resource is located at byte offset %ld.",

           GetCtResource(datno, "MY!resource", &my_resource,

                         1024L, RES_NAME));

} else

    printf("\nCould not add resource. Error #%d",uerr_cod);

See also

GetCtResource, UpdateCtResource, and DeleteCtResource. Also refer to Resources.