Jump to content

DosFreeResource: Difference between revisions

From EDM2
Ak120 (talk | contribs)
Ak120 (talk | contribs)
mNo edit summary
Line 1: Line 1:
==Description==
Frees a resource that was loaded by DosGetResource.
Frees a resource that was loaded by DosGetResource.


==Syntax==
==Syntax==
<PRE>
DosFreeResource (pb)
#define INCL_DOSMODULEMGR
#include <os2.h>


PVOID    pb;    /*  The address of the resource to be freed. */
APIRET    ulrc;  /*  Return Code. */
ulrc = DosFreeResource(pb);
</PRE>
==Parameters==
==Parameters==
; pb (PVOID) - input : The address of the resource to be freed.
;pb (PVOID) - input : The address of the resource to be freed.


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


==Remarks==
==Remarks==
DosFreeResource frees a resource that was loaded by DosGetResource.
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.  
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==
==Example Code==
Line 73: Line 62:
return NO_ERROR;
return NO_ERROR;
}
}
</PRE>


</PRE>
==Related Functions==
==Related Functions==
* [[OS2 API:CPI:DosGetResource|DosGetResource]]
* [[DosGetResource]]
 


[[Category:The OS/2 API Project]]
[[Category:Dos]]

Revision as of 10:35, 13 February 2017

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.

#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