Hitachi

JP1 Version 11 JP1/Script Description and Reference (For Windows Systems)


10.3 Coding example of a script control interface

A coding example of a script control interface is shown below.

Example

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "sthapi.h"
 
BOOL    TerminateScript(LPCSTR lpszNetName, LPCSTR lpszFileName, UINT    uProcessID)
{
    HKEY            hKey;
    LPCSTR          subKey =
                    "SOFTWARE\\Hitachi\\JP1/Script\\PathName";
    char            valueName[32];
    char            value[_MAX_PATH];
    DWORD           valueSize = sizeof(value);
    HINSTANCE       hAPIInstance;
    tSPTHOpen       pSPTHOpen;
    tSPTHClose      pSPTHClose;
    tSPTHTerminate  pSPTHTerminate;
    HANDLE          hScript;
 
    // Open the registry.
    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, subKey, 0,
         KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
    {
        // Error processing
        return(FALSE);
    }
 
    // Get the "SPTHL.DLL" path.
    strcpy(valueName, "Path01");
    if(RegQueryValueEx(hKey, valueName, 0, NULL,(LPBYTE) value, &valueSize) != ERROR_SUCCESS)
    {
        // Error processing
        return(FALSE);
    }
 
    // Load "SPTHL.DLL".
    strcat(value, "\\SPTHL.DLL");
    hAPIInstance = LoadLibraryEx(value, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
    if(hAPIInstance == NULL)
    {
        // Error processing
        return(FALSE);
    }
 
    // Get the entry point of each function.
    pSPTHOpen = (tSPTHOpen) GetProcAddress(hAPIInstance, "SPTHOpen");
    pSPTHClose = (tSPTHClose) GetProcAddress(hAPIInstance, "SPTHClose");
    pSPTHTerminate = (tSPTHTerminate(GetProcAddress(hAPIInstance, "SPTHTerminate");
 
    // Open DLL.
    if(pSPTHOpen(lpszNetName, NULL, &hScript) == FALSE)
    {
        FreeLibrary(hAPIInstance);
        return(FALSE);
    }
 
    // Forcibly terminate script execution.
    if (pSPTHTerminate(hScript, lpszFileName, uProcessID, SPTH_TERM_CHILD) == FALSE)
    {
        pSPTHClose(hScript);
        FreeLibrary(hAPIInstance);
        return(FALSE);
    }
 
    // Close DLL.
    pSPTHClose(hScript);
 
    // Release the API interface handle.
    FreeLibrary(hAPIInstance);
 
    return(TRUE);
}