|
![]() |
![]() |
version 2003
PA_CreateResource (resFile; kind; resID; name; resData; dataSize) → short
Parameter | Type | Description | |
resFile | short | → | File reference number of the file to access |
kind | unsigned long | → | Kind (4 Bytes type) of resource to create |
resID | short | → | Unique resource ID (or -1) |
name | char* | → | Resource name |
resData | char* | → | Resource data pointer |
dataSize | long | → | Sizes of resData in bytes |
Function result | short | ← | Unique ID for this resource |
Description
The routine
PA_CreateResource
adds a resource of type
kind
and unique number
ID
to the resource file
resFile
. The resource will be filled with the data pointed by
resData
.
Pass in
resFile
the reference number of the file to access (obtained with
PA_CreateResFile
,
PA_OpenResFile
,
PA_GetDatabaseResFile
).
In
kind
, you pass the 4-bytes type of the resource ('TEXT', 'PICT', 'toto').
Pass in
resID
the unique ID of the resource you want to create. If you pass -1 in
resID
, then 4th Dimension will find a unique ID for you.
In
name
, pass a string and the name of the resource (it can be a null string). Depending on default settings or on previous calls to
PA_UsePStrings
or
PA_UseCStrings
,
name
will be either a Pascal or ANSI C string.
In
resData
, pass a pointer to the data of the new resource and its size in bytes in
dataSize
.
If the resources has been successfully created,
PA_GetLastError
is set to
eER_NoErr
and the routine returns the ID (it will be equal to
resID
if it was not -1).
IMPORTANT NOTE
If a resource of the same kind and the same ID already exists,
PA_CreateResource
overwrites it without generating any error.
Examples
(1) Wrap the routine to ensure that we do not overwrite an existing resource. To do this, use
PA_GetResourceHandle
that returns 0 if the specified resource does not exist.
short myCreateResource(short resFile, unsigned long kind, short resID, char *name, char *data, long size)
{
// if resID is -1, 4D will find an unique ID for us. We do not care in this case.
if(resID != -1)
{
PA_Handle h = PA_GetResourceHandle(resFile, kind, resID);
if(h) // the same resource already exists. Return the error, but first release memory
{
PA_DetachResource(resFile, h);
PA_DisposeHandle(h);
MyGenerateError (kMY_ERROR_CODE_RESOURCE_EXISTS);
return -1; // this must be checked in the calling routine
}
}
// We are here: the resource does not exists, or resID is -1.
return PA_CreateResource(resFile, kind, resID, data, size);
}
(2)Create a new resource based on a private structure (using the previous wrapper)
typedef struct
{
long f1;
long f2;
long f3;
long f4;
} AStructure;
#define
short Add_AStructureResource(short resFile, AStructure *toAdd, char *name)
{
return myCreateResource(resFile,
'Tißo',
-1, // let 4D find an ID and return it
name,
(char *) toAdd,
sizeof(AStructure));
}
See Also
Error Handling
Use
PA_GetLastError
to see if an error occurred