Dynamic Link Method

Using the dynamic link method the application makes calls to the operating system at run time to load the Z and I Emulator for Windows EHLLAPI module and to locate the hllapi entry point within it. This method requires more code in the application but gives the application greater control over error conditions. For example, the application can display a specific error message to the user if the Z and I Emulator for Windows EHLLAPI module cannot be found.

To use dynamic linking, the application needs to load the appropriate Z and I Emulator for Windows module and locate the entry point. It is recommended that the entry point be located by its ordinal number and not by name. The ordinal number is defined in the header file. The following 32-bit Windows® code loads the IBM® Standard 32-bit EHLLAPI module, locates the hllapi entry point, and makes an EHLLAPI function call.
  #include "hapi_c.h"
 
  HMODULE Hmod;                                         // Handle of PCSHLL32.DLL
  long (APIENTRY hllapi)(int *, char *, int *, int *);  // Function pointer
  int HFunc, HLen, HRc;                                 // Function parameters
  char HBuff[1];                                        // Function parameters
 
  Hmod = LoadLibrary("PCSHLL32.DLL");                   // Load EHLLAPI module
  if (Hmod == NULL) {
    // ... Error, cannot load EHLLAPI module
  }
 
  hllapi = GetProcAddress(Hmod, MAKEINTRESOURCE(ord_hllapi));
                                                       // Get EHLLAPI entry point
  if (hllapi == NULL) {
    // ... Error, cannot find EHLLAPI entry point
  }
 
  HFunc = HA_RESET_SYSTEM;                              // Run EHLLAPI function
  HLen  = 0;
  HRc   = 0;
  (*hllapi)(&Func, HBuff, &HLen, &HRc);
  if (HRc != 0) {
    // ... EHLLAPI access error
  }