DosFreeResource: Difference between revisions
Appearance
m Ak120 moved page OS2 API:CPI:DosFreeResource to DosFreeResource |
mNo edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
Frees a resource that was loaded by DosGetResource. | Frees a resource that was loaded by DosGetResource. | ||
==Syntax== | ==Syntax== | ||
DosFreeResource (pb) | |||
==Parameters== | ==Parameters== | ||
; | ;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 | * 5 ERROR_ACCESS_DENIED | ||
* 5 | |||
==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> | |||
==Related Functions== | ==Related Functions== | ||
* [[ | * [[DosGetResource]] | ||
[[Category: | [[Category:Dos]] |
Latest revision as of 18:29, 6 January 2023
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; }