gtpc2m1mC/C++ Language Support User's Guide

dllfree-Free the Supplied Dynamic Link Library (DLL)

This function frees the supplied DLL handle and logically deletes the DLL from memory if the handle was the last handle accessing the DLL.

Format

#include <dll.h>
int dllfree(dllhandle* dllHandle);

dllHandle
A pointer to the dllhandle structure that is described in the dll.h header file.

Normal Return

The dllfree function returns the following value when the requested service has been performed.

Value
Meaning

0
Successful

Error Return

The dllfree function returns one of the following values and sets errno if the return code is not 0:

Value
Meaning

1
The dllHandle supplied is NULL or dllHandle is inactive.

2
There are no DLLs to be deleted.

3
A logical delete was performed, but the DLL is not physically deleted because the DLCB use count is > 1 or there is an implicit reference to the DLL.
Note:
DLCB is an IBM internal-use-only control block.

4
No match is found for input dllHandle.

5
C++ destructors are currently running for this DLL. A dllfree function is already in progress.

Programming Considerations

Examples

The following example shows how to use the dllfree function to free the dllHandle, which is in DLL load module DLLB.

#include <stdio.h>
#include <dll.h>
 
int DLLA (void);
int DLLA() {
  dllhandle *handle;
  char *name="DLLB";
  int (*fptr1)(int);
  int *ptr1_var1;
  int rc=0;
 
  handle = dllload(name);          /* call to stream DLL */
  if (handle == NULL) {
     printf("failed on call to DLLB DLL\n");
     exit(-1);
  }
 
  fptr1 = (int (*)(int)) dllqueryfn(handle,"f1");
                                      /* retrieving f1 function  */
  if (ftpr1 == NULL) {
     printf("failed on retrieving f1 function\n");
     exit(-2);
  }
 
  ptr1_var1 = dllqueryvar(handle,"var1");
                                     /* retrieving var1 variable  */
  if (ptr1_var1 == NULL) {
     printf("failed on retrieving var1 variable\n");
     exit(-3);
  }
 
  rc = fptr1(*ptr1_var1);    /* execute DLL function f1 */
  (*ptr1_var1)++;            /* increment value of var1 */
 
  rc = dllfree(handle);    /* freeing handle to DLLB   DLL */
  if (rc != 0) {
     printf("failed on dllfree call\n");
 
  }
  return (0);
}

Related Information