Dynamic Link Method

Using the dynamic link method the application makes calls to the operating system at run time to load the Personal Communications 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 Personal Communications EHLLAPI module cannot be found.

To use dynamic linking, the application needs to load the appropriate Personal Communications 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
  }

The following is similar code for 32–bit OS/2®:

#include "hapi_c.h"
 
HMODULE Hmod;                                       // ACS3EHAP.DLL handle
long (* APIENTRY hllapi)(int *, char *, int *, int *); // Func ptr
int HFunc, HLen, HRc;                                  // Func parms
char HBuff[1];                                         // Func parms
 
if (DosLoadModule(NULL, 0, "ACS3EHAP", &HMod) != 0) {  // Load HLLAPI module
  // ...Error, cannot load EHLLAPI module
}
 
// Get EHLLAPI entry point
if (DosQueryProcAddr(Hmod, ord_hllapi, NULL, (PFN *)&hlappi) != 0) {
  // ...Error, cannot find EHLLAPI entry point
}
 
HFunc = HA_RESET_SYSTEM;                            // Run HLLAPI function
HLen  = 0;
HRc   = 0;
(*hllapi)(&HFunc, HBuff, &HLen, &HRc);
if (HRc != 0) {
  // ... EHLLAPI access error
}