Difference between revisions of "DosFreeModule"
From EDM2
m |
m |
||
(One intermediate revision by one user not shown) | |||
Line 2: | Line 2: | ||
==Syntax== | ==Syntax== | ||
− | + | DosFreeModule (hmod) | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
==Parameters== | ==Parameters== | ||
− | ;HMODULE ''hMod'' (input) : Handle for the module to be freed (from DosLoadModule). | + | ;HMODULE ''hMod'' (input) : Handle for the module to be freed (from [[DosLoadModule]]). |
==Returns== | ==Returns== | ||
− | ulrc (APIRET) - returns | + | ulrc (APIRET) - returns |
− | ;APIRET rc: Indicates if any error occurred. | + | ;APIRET rc: Indicates if any error occurred. |
− | {| | + | {| |
− | |0 | + | |0||NO_ERROR |
− | |NO_ERROR | + | |
|- | |- | ||
− | |6 | + | |6||ERROR_INVALID_HANDLE |
− | |ERROR_INVALID_HANDLE | + | |
|- | |- | ||
− | |12 | + | |12||ERROR_INVALID_ACCESS |
− | |ERROR_INVALID_ACCESS | + | |
|- | |- | ||
− | |95 | + | |95||ERROR_INTERRUPT |
− | |ERROR_INTERRUPT | + | |
|} | |} | ||
Line 49: | Line 39: | ||
return(-1); | return(-1); | ||
} | } | ||
− | |||
This example loads, queries, and then frees the dynamic link module "DISPLAY.DLL". | This example loads, queries, and then frees the dynamic link module "DISPLAY.DLL". | ||
<PRE> | <PRE> |
Latest revision as of 16:49, 6 January 2023
Frees the reference to the dynamic link module for this process.
Contents
Syntax
DosFreeModule (hmod)
Parameters
- HMODULE hMod (input)
- Handle for the module to be freed (from DosLoadModule).
Returns
ulrc (APIRET) - returns
- APIRET rc
- Indicates if any error occurred.
0 | NO_ERROR |
6 | ERROR_INVALID_HANDLE |
12 | ERROR_INVALID_ACCESS |
95 | ERROR_INTERRUPT |
Include Info
#define INCL_DOSMODULEMGR #include <os2.h>
Usage Explanation
DosFreeModule frees the reference to the dynamic link module for this process and if the dynamic link module is not used by any other process the memory occupied by the module is freed. This means that no functions in the dynamic link module can be used any longer.
Sample Code
HMODULE hmod; APIRET rc=0; /* Load DLL with DosLoadModule */ /* Free DLL */ rc = DosFreeModule(hmod); if(rc) { /* Not success? */ printf("Error. Cannot free the DLL. DosFreeModule returned %d.\n",rc); return(-1); }
This example loads, queries, and then frees the dynamic link module "DISPLAY.DLL".
#define INCL_DOSMODULEMGR /* Module Manager values */ #define INCL_DOSERRORS /* Error values */ #include <os2.h> #include <stdio.h> int main(VOID) { PSZ ModuleName = "C:\\OS2\\DLL\\DISPLAY.DLL"; /* Name of module */ UCHAR LoadError[256] = ""; /* Area for Load failure information */ HMODULE ModuleHandle = NULLHANDLE; /* Module handle */ PFN ModuleAddr = 0; /* Pointer to a system function */ ULONG ModuleType = 0; /* Module type */ APIRET rc = NO_ERROR; /* Return code */ rc = DosLoadModule(LoadError, /* Failure information buffer */ sizeof(LoadError), /* Size of buffer */ ModuleName, /* Module to load */ &ModuleHandle); /* Module handle returned */ if (rc != NO_ERROR) { printf("DosLoadModule error: return code = %u\n", rc); return 1; } else { printf("Module %s loaded.\n", ModuleName); } /* endif */ rc = DosQueryProcAddr(ModuleHandle, /* Handle to module */ 1L, /* No ProcName specified */ NULL, /* ProcName (not specified) */ &ModuleAddr); /* Address returned */ if (rc != NO_ERROR) { printf("DosQueryProcAddr error: return code = %u\n", rc); return 1; } else printf("Address of module is 0x%x.\n", ModuleAddr); rc = DosQueryProcType(ModuleHandle, /* Handle to module */ 1L, /* Indicate no ProcName given */ NULL, /* ProcName (not specified) */ &ModuleType); /* Type 0=16-bit 1=32-bit */ if (rc != NO_ERROR) { printf("DosQueryProcType error: return code = %u\n", rc); return 1; } else printf("This is a %s module.\n", ( ModuleType ? "32-bit" : "16-bit")); rc = DosFreeModule(ModuleHandle); if (rc != NO_ERROR) { printf("DosFreeModule error: return code = %u\n", rc); return 1; } else printf("Module %s freed.\n", ModuleName); return NO_ERROR; }