DosFreeResource

Frees a resource that was loaded by DosGetResource.

Syntax
DosFreeResource (pb)

Parameters

 * pb (PVOID) - input : The address of the resource to be freed.

Return Code
ulrc (APIRET) - returns DosFreeResource returns one of the following values:
 * 0  NO_ERROR
 * 5  ERROR_ACCESS_DENIED

Remarks
DosFreeResource frees a resource that was loaded by DosGetResource.

After the last reference to a resource is freed, the memory becomes available for reuse by the system; however, the memory is not reused until the system determines that it cannot satisfy a memory allocation request. This allows the resource to remain in memory in case the process issues DosGetResource again. The system thus avoids having to read the contents of the resource from the disk again.

Example Code
This example loads the dynamic link module "DISPLAY.DLL", gets a resource, and then releases it. 
 * 1) define INCL_DOSRESOURCES    /* Resource types */
 * 2) define INCL_DOSMODULEMGR    /* Module Manager values */
 * 3) define INCL_DOSERRORS       /* DOS error values */
 * 4) include 
 * 5) include 

int main(VOID) { UCHAR    LoadError[256] = "";         /* Area for Load failure information */ PSZ      ModuleName = "C:\\OS2\\DLL\\PMWP.DLL";  /* DLL with resources */ HMODULE  ModHandle  = NULLHANDLE;        /* Handle for module */ PVOID    Offset     = NULL;              /* Pointer to resource */ APIRET   rc         = NO_ERROR;          /* API return code */

rc = DosLoadModule(LoadError,              /* Failure information buffer */                    sizeof(LoadError),       /* Size of buffer             */                    ModuleName,              /* Module to load             */                    &ModHandle);             /* Module handle returned     */ if (rc != NO_ERROR) { printf("DosLoadModule error: return code = %u\n", rc); return 1; }

rc = DosGetResource(ModHandle,    /* Handle for DLL containing resources */                     RT_POINTER,    /* Ask for  Pointer                    */                     1L,            /*          with an ID of 1            */                     &Offset);      /* Get back pointer                    */ if (rc != NO_ERROR) { printf("DosGetResource error: return code = %u\n", rc); return 1; } else { printf("Resource Offset = 0x%x\n", Offset); } /* endif */

rc = DosFreeResource(Offset); if (rc != NO_ERROR) { printf("DosFreeResource error: return code = %u\n", rc); return 1; }

return NO_ERROR; } 

Related Functions

 * DosGetResource