DosFreeModule

From EDM2
Revision as of 20:18, 23 December 2016 by Ak120 (Talk | contribs)

Jump to: navigation, search

Frees the reference to the dynamic link module for this process.

Syntax

#define INCL_DOSMODULEMGR
#include <os2.h>

HMODULE    hmod;  /*  The handle of the dynamic link module that is to be freed. */
APIRET     ulrc;  /*  Return Code. */

ulrc = 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;
}

Related Functions