PA_LockResource

4D - Documentation   Français   English   German   4D Plugin API, Command Theme List   4D Plugin API, Command Alphabetical List   Back   Previous   Next

version 2003


PA_LockResource (resfile; kind; resID) char

ParameterTypeDescription
resfileshortFile reference number of the file to access
kindunsigned longKind (4 Bytes type) of resource to access
resIDshortUnique resource ID
Function resultchar1 = The resource has been locked. 0 = Already in use

Description

The routine PA_LockResource tries to lock the resource of type kind and the ID resID of the file resFile over the network; it returns 1 if successfully locked, and 0 if the resource is already in use by an other client.

You should always lock the resource before modifying it so that no one can modify it while you read or modify it. Once a resource is locked, it can not be modified by another process and it can neither be disposed or nor purged from memory.

If the resource does not exist or if resFile is an invalid file reference number, the routine does nothing and PA_GetLastError returns -5 ("Resource not found").

It is not necessary to lock the resource if the plug-in only wants to read it.

WARNING

In 4D single-user, the routine always returns 1. It is the plug-in's responsibility to manage multiprocess access in this case.

Example

Lock the resource 'pipf' ID 128.

   typedef struct {
      short   f1;
      short   f2;
      long   f3;
      /* ... */
   }PLUG_PREFS;

   // Lock the resource
   if( PA_LockResource(resFile, 'pipf', 128))
   {
   // Ok, no one can modify it on an other machine
   // Initialize one structure
      PLUG_PREFS   h = {1, 2, 3};
   // Change the resource content
      PA_SetResource(resFile, 'pipf', 128, (char *) &prefs, sizeof(PLUG_PREFS));
   //write the resource
      PA_Write(resFile)
   // Unlock it
      PA_Unlockresource(resFile, 'pipf', 128);
   }

See Also

About the internal resource manager, PA_GetResource, PA_UnlockResource.

Error Handling

Use PA_GetLastError to see if an error occurred


4D - Documentation   Français   English   German   4D Plugin API, Command Theme List   4D Plugin API, Command Alphabetical List   Back   Previous   Next