Jump to content

DosFreeResource

From EDM2
Revision as of 07:30, 9 January 2017 by Ak120 (talk | contribs) (Ak120 moved page OS2 API:CPI:DosFreeResource to DosFreeResource)

Description

Frees a resource that was loaded by DosGetResource.

Syntax

#define INCL_DOSMODULEMGR
#include <os2.h>

PVOID     pb;    /*  The address of the resource to be freed. */
APIRET    ulrc;  /*  Return Code. */

ulrc = 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.

#define INCL_DOSRESOURCES     /* Resource types */
#define INCL_DOSMODULEMGR     /* Module Manager values */
#define INCL_DOSERRORS        /* DOS error values */
#include <os2.h>
#include <stdio.h>

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