动态链接方法
使用动态链接方法,应用程序可在运行时调用操作系统,以装入 Z and I Emulator for Windows EHLLAPI 模块并在其中找到 hllapi。此方法在应用程序中需要更多代码,但使应用程序能够更好地控制错误情况。例如,如果找不到 Z and I Emulator for Windows EHLLAPI 模块,应用程序可以向用户显示特定的错误消息。
要使用动态链接,应用程序需要装入相应的 Z and I Emulator for Windows 模块并找到入口点。建议按序号而非名称找到入口点。可在头文件中定义此序号.以下 32 位 Windows® 代码将装入 IBM® 标准 32 位 EHLLAPI 模块,找到 hllapi 入口点,以及进行 EHLLAPI 函数调用。
#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
}