C# Halcon引擎底层

4 篇文章 0 订阅
using HalconDotNet;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;

namespace HDev
{
    internal delegate int DevOpenWindowDelegate(IntPtr row, IntPtr column, IntPtr width, IntPtr height, IntPtr background, IntPtr windowID);
    internal delegate int DevCloseWindowDelegate();
    internal delegate int DevSetWindowDelegate(IntPtr windowID);
    internal delegate int DevGetWindowDelegate(IntPtr windowID);
    internal delegate int DevSetWindowExtentsDelegate(IntPtr row, IntPtr column, IntPtr width, IntPtr height);
    internal delegate int DevSetPartDelegate(IntPtr row1, IntPtr column1, IntPtr row2, IntPtr column2);
    internal delegate int DevClearWindowDelegate();
    internal delegate int DevDisplayDelegate(IntPtr key);
    internal delegate int DevDispTextDelegate(IntPtr text, IntPtr coordSystem, IntPtr row, IntPtr column, IntPtr color, IntPtr genParamNames, IntPtr genParamValues);
    internal delegate int DevSetDrawDelegate(IntPtr draw);
    internal delegate int DevSetContourStyleDelegate(IntPtr style);
    internal delegate int DevSetShapeDelegate(IntPtr shape);
    internal delegate int DevSetColoredDelegate(IntPtr colored);
    internal delegate int DevSetColorDelegate(IntPtr color);
    internal delegate int DevSetLutDelegate(IntPtr lut);
    internal delegate int DevSetPaintDelegate(IntPtr paint);
    internal delegate int DevSetLineWidthDelegate(IntPtr width);
    //     Communication with hdevengine.dll
    [SuppressUnmanagedCodeSecurity]
    internal class EngineAPI
    {
        private const string EngineDLL = "hdevenginecppxl";

        private const CallingConvention EngineCall = CallingConvention.Cdecl;

        internal const int H_MSG_OK = 2;

        internal const int H_MSG_TRUE = 2;

        internal const int H_MSG_FALSE = 3;

        internal const int H_MSG_VOID = 4;

        internal const int H_MSG_FAIL = 5;

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenCreateEngine")]
        internal static extern int CreateEngine(out IntPtr engine);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenDestroyEngine")]
        internal static extern int DestroyEngine(IntPtr engine);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetEngineAttribute")]
        internal static extern int SetEngineAttribute(IntPtr engine, string name, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetEngineAttribute")]
        internal static extern int GetEngineAttribute(IntPtr engine, string name, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenStartDebugServer")]
        internal static extern int StartDebugServer(IntPtr engine);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenStopDebugServer")]
        internal static extern int StopDebugServer(IntPtr engine);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl)]
        internal static extern int HCenSetProcedurePath(IntPtr engine, IntPtr path_utf8);

        internal static int SetProcedurePath(IntPtr engine, string path)
        {
            IntPtr intPtr = HalconAPI.ToHGlobalUtf8Encoding(path);
            int result = HCenSetProcedurePath(engine, intPtr);
            Marshal.FreeHGlobal(intPtr);
            return result;
        }

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl)]
        internal static extern int HCenAddProcedurePath(IntPtr engine, IntPtr path_utf8);

        internal static int AddProcedurePath(IntPtr engine, string path)
        {
            IntPtr intPtr = HalconAPI.ToHGlobalUtf8Encoding(path);
            int result = HCenAddProcedurePath(engine, intPtr);
            Marshal.FreeHGlobal(intPtr);
            return result;
        }

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetHDevOperatorImpl")]
        internal static extern int SetHDevOperatorImpl(IntPtr engine, IntPtr implementation);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetProcedureNames")]
        internal static extern int GetProcedureNames(IntPtr engine, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetLoadedProcedureNames")]
        internal static extern int GetLoadedProcedureNames(IntPtr engine, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenUnloadProcedure")]
        internal static extern int UnloadProcedure(IntPtr engine, string name);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenUnloadAllProcedures")]
        internal static extern int UnloadAllProcedures(IntPtr engine);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetGlobalIconicVarNames")]
        internal static extern int GetGlobalIconicVarNames(IntPtr engine, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetGlobalCtrlVarNames")]
        internal static extern int GetGlobalCtrlVarNames(IntPtr engine, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetGlobalCtrlVarDimension")]
        internal static extern int GetGlobalCtrlVarDimension(IntPtr engine, string name, out int dimension);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetGlobalIconicVarDimension")]
        internal static extern int GetGlobalIconicVarDimension(IntPtr engine, string name, out int dimension);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetGlobalCtrlVarTuple")]
        internal static extern int GetGlobalCtrlVarTuple(IntPtr engine, string name, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetGlobalCtrlVarVector")]
        internal static extern int GetGlobalCtrlVarVector(IntPtr engine, string name, out IntPtr vector);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetGlobalIconicVarObject")]
        internal static extern int GetGlobalIconicVarObject(IntPtr engine, string name, out IntPtr key);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetGlobalIconicVarVector")]
        internal static extern int GetGlobalIconicVarVector(IntPtr engine, string name, out IntPtr vector);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetGlobalCtrlVarTuple")]
        internal static extern int SetGlobalCtrlVarTuple(IntPtr engine, string name, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetGlobalCtrlVarVector")]
        internal static extern int SetGlobalCtrlVarVector(IntPtr engine, string name, IntPtr vector);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetGlobalIconicVarObject")]
        internal static extern int SetGlobalIconicVarObject(IntPtr engine, string name, IntPtr key);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetGlobalIconicVarVector")]
        internal static extern int SetGlobalIconicVarVector(IntPtr engine, string name, IntPtr vector);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenCreateProgram")]
        internal static extern int CreateProgram(out IntPtr program);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenDestroyProgram")]
        internal static extern int DestroyProgram(IntPtr program);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl)]
        internal static extern int HCenLoadProgram(IntPtr program, IntPtr fileName);

        internal static int LoadProgram(IntPtr program, string fileName)
        {
            IntPtr intPtr = HalconAPI.ToHGlobalUtf8Encoding(fileName);
            int result = HCenLoadProgram(program, intPtr);
            Marshal.FreeHGlobal(intPtr);
            return result;
        }

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl)]
        private static extern int HCenGetProgramInfo(IntPtr program, out IntPtr name, out bool loaded, IntPtr varNamesIconic, IntPtr varNamesCtrl, IntPtr varDimsIconic, IntPtr varDimsCtrl);

        internal static void GetProgramInfo(IntPtr program, out string name, out bool loaded, out HTuple varNamesIconic, out HTuple varNamesCtrl, out HTuple varDimsIconic, out HTuple varDimsCtrl)
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(HalconAPI.CreateTuple(out var tuple2));
            HCkE(HalconAPI.CreateTuple(out var tuple3));
            HCkE(HalconAPI.CreateTuple(out var tuple4));
            HCkE(HCenGetProgramInfo(program, out var name2, out loaded, tuple, tuple2, tuple3, tuple4));
            name = Marshal.PtrToStringAnsi(name2);
            varNamesIconic = HalconAPI.LoadTuple(tuple);
            varNamesCtrl = HalconAPI.LoadTuple(tuple2);
            varDimsIconic = HalconAPI.LoadTuple(tuple3);
            varDimsCtrl = HalconAPI.LoadTuple(tuple4);
            HCkE(HalconAPI.DestroyTuple(tuple));
            HCkE(HalconAPI.DestroyTuple(tuple2));
            HCkE(HalconAPI.DestroyTuple(tuple3));
            HCkE(HalconAPI.DestroyTuple(tuple4));
        }

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenProgGetUsedProcedureNames")]
        internal static extern int GetUsedProcedureNamesForProgram(IntPtr program, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenProgGetLocalProcedureNames")]
        internal static extern int GetLocalProcedureNames(IntPtr program, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenProgCompileUsedProcedures")]
        internal static extern int CompileUsedProceduresForProgram(IntPtr program, out bool ret);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenCreateProgramCall")]
        internal static extern int CreateProgramCall(IntPtr program, out IntPtr call);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenDestroyProgramCall")]
        internal static extern int DestroyProgramCall(IntPtr call);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenExecuteProgramCall")]
        internal static extern int ExecuteProgramCall(IntPtr call);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetWaitForDebugConnectionProgramCall")]
        internal static extern int SetWaitForDebugConnectionProgramCall(IntPtr call, bool wait_once);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenResetProgramCall")]
        internal static extern int ResetProgramCall(IntPtr call);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetCtrlVarTupleIndex")]
        internal static extern int GetCtrlVarTuple(IntPtr call, int index, out IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetCtrlVarVectorIndex")]
        internal static extern int GetCtrlVarVector(IntPtr call, int index, out IntPtr vector);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetCtrlVarTupleName")]
        internal static extern int GetCtrlVarTuple(IntPtr call, string name, out IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetCtrlVarVectorName")]
        internal static extern int GetCtrlVarVector(IntPtr call, string name, out IntPtr vector);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetIconicVarObjectIndex")]
        internal static extern int GetIconicVarObject(IntPtr call, int index, out IntPtr key);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetIconicVarVectorIndex")]
        internal static extern int GetIconicVarVector(IntPtr call, int index, out IntPtr vector);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetIconicVarObjectName")]
        internal static extern int GetIconicVarObject(IntPtr call, string name, out IntPtr key);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetIconicVarVectorName")]
        internal static extern int GetIconicVarVector(IntPtr call, string name, out IntPtr vector);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenCreateProcedure")]
        internal static extern int CreateProcedure(out IntPtr procedure);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenDestroyProcedure")]
        internal static extern int DestroyProcedure(IntPtr procedure);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenLoadProcedure")]
        internal static extern int LoadProcedure(IntPtr procedure, string procedureName);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl)]
        internal static extern int HCenLoadProcedureProgramName(IntPtr procedure, IntPtr programName, string procedureName);

        internal static int LoadProcedure(IntPtr procedure, string programName, string procedureName)
        {
            IntPtr intPtr = HalconAPI.ToHGlobalUtf8Encoding(programName);
            int result = HCenLoadProcedureProgramName(procedure, intPtr, procedureName);
            Marshal.FreeHGlobal(intPtr);
            return result;
        }

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenLoadProcedureProgram")]
        internal static extern int LoadProcedure(IntPtr procedure, IntPtr program, string procedureName);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl)]
        private static extern int HCenGetProcedureInfo(IntPtr procedure, out IntPtr name, out IntPtr shortDescription, out bool loaded, IntPtr parNamesIconicInput, IntPtr parNamesIconicOutput, IntPtr parNamesCtrlInput, IntPtr parNamesCtrlOutput, IntPtr parDimsIconicInput, IntPtr parDimsIconicOutput, IntPtr parDimsCtrlInput, IntPtr parDimsCtrlOutput);

        internal static void GetProcedureInfo(IntPtr procedure, out string name, out string shortDescription, out bool loaded, out HTuple parNamesIconicInput, out HTuple parNamesIconicOutput, out HTuple parNamesCtrlInput, out HTuple parNamesCtrlOutput, out HTuple parDimsIconicInput, out HTuple parDimsIconicOutput, out HTuple parDimsCtrlInput, out HTuple parDimsCtrlOutput)
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(HalconAPI.CreateTuple(out var tuple2));
            HCkE(HalconAPI.CreateTuple(out var tuple3));
            HCkE(HalconAPI.CreateTuple(out var tuple4));
            HCkE(HalconAPI.CreateTuple(out var tuple5));
            HCkE(HalconAPI.CreateTuple(out var tuple6));
            HCkE(HalconAPI.CreateTuple(out var tuple7));
            HCkE(HalconAPI.CreateTuple(out var tuple8));
            HCkE(HCenGetProcedureInfo(procedure, out var name2, out var shortDescription2, out loaded, tuple, tuple2, tuple3, tuple4, tuple5, tuple6, tuple7, tuple8));
            name = HalconAPI.FromHalconEncoding(name2, force_utf8: true);
            shortDescription = HalconAPI.FromHalconEncoding(shortDescription2, force_utf8: true);
            parNamesIconicInput = HalconAPI.LoadTuple(tuple);
            parNamesIconicOutput = HalconAPI.LoadTuple(tuple2);
            parNamesCtrlInput = HalconAPI.LoadTuple(tuple3);
            parNamesCtrlOutput = HalconAPI.LoadTuple(tuple4);
            parDimsIconicInput = HalconAPI.LoadTuple(tuple5);
            parDimsIconicOutput = HalconAPI.LoadTuple(tuple6);
            parDimsCtrlInput = HalconAPI.LoadTuple(tuple7);
            parDimsCtrlOutput = HalconAPI.LoadTuple(tuple8);
            HCkE(HalconAPI.DestroyTuple(tuple));
            HCkE(HalconAPI.DestroyTuple(tuple2));
            HCkE(HalconAPI.DestroyTuple(tuple3));
            HCkE(HalconAPI.DestroyTuple(tuple4));
            HCkE(HalconAPI.DestroyTuple(tuple5));
            HCkE(HalconAPI.DestroyTuple(tuple6));
            HCkE(HalconAPI.DestroyTuple(tuple7));
            HCkE(HalconAPI.DestroyTuple(tuple8));
        }

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenProcGetUsedProcedureNames")]
        internal static extern int GetUsedProcedureNamesForProcedure(IntPtr procedure, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenProcCompileUsedProcedures")]
        internal static extern int CompileUsedProceduresForProcedure(IntPtr procedure, out bool ret);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenProcGetInfo")]
        internal static extern int GetProcInfo(IntPtr procedure, string slot, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenProcGetParamInfo")]
        internal static extern int GetParamInfo(IntPtr procedure, string parName, string slot, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenProcGetInputIconicParamInfo")]
        internal static extern int GetInputIconicParamInfo(IntPtr procedure, int parIdx, string slot, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenProcGetOutputIconicParamInfo")]
        internal static extern int GetOutputIconicParamInfo(IntPtr procedure, int parIdx, string slot, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenProcGetInputCtrlParamInfo")]
        internal static extern int GetInputCtrlParamInfo(IntPtr procedure, int parIdx, string slot, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenProcGetOutputCtrlParamInfo")]
        internal static extern int GetOutputCtrlParamInfo(IntPtr procedure, int parIdx, string slot, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenProcQueryInfo")]
        internal static extern int QueryInfo(IntPtr procedure, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenProcQueryParamInfo")]
        internal static extern int QueryParamInfo(IntPtr procedure, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenCreateProcedureCall")]
        internal static extern int CreateProcedureCall(IntPtr program, out IntPtr call);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenDestroyProcedureCall")]
        internal static extern int DestroyProcedureCall(IntPtr call);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenExecuteProcedureCall")]
        internal static extern int ExecuteProcedureCall(IntPtr call);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetWaitForDebugConnectionProcedureCall")]
        internal static extern int SetWaitForDebugConnectionProcedureCall(IntPtr call, bool wait_once);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenResetProcedureCall")]
        internal static extern int ResetProcedureCall(IntPtr call);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetInputCtrlParamTupleIndex")]
        internal static extern int SetInputCtrlParamTuple(IntPtr call, int index, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetInputCtrlParamTupleName")]
        internal static extern int SetInputCtrlParamTuple(IntPtr call, string name, IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetInputCtrlParamVectorIndex")]
        internal static extern int SetInputCtrlParamVector(IntPtr call, int index, IntPtr vector);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetInputCtrlParamVectorName")]
        internal static extern int SetInputCtrlParamVector(IntPtr call, string name, IntPtr vector);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetInputIconicParamObjectIndex")]
        internal static extern int SetInputIconicParamObject(IntPtr call, int index, IntPtr key);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetInputIconicParamObjectName")]
        internal static extern int SetInputIconicParamObject(IntPtr call, string name, IntPtr key);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetInputIconicParamVectorIndex")]
        internal static extern int SetInputIconicParamVector(IntPtr call, int index, IntPtr key);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetInputIconicParamVectorName")]
        internal static extern int SetInputIconicParamVector(IntPtr call, string name, IntPtr key);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetOutputCtrlParamTupleIndex")]
        internal static extern int GetOutputCtrlParamTuple(IntPtr call, int index, out IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetOutputCtrlParamTupleName")]
        internal static extern int GetOutputCtrlParamTuple(IntPtr call, string name, out IntPtr tuple);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetOutputCtrlParamVectorIndex")]
        internal static extern int GetOutputCtrlParamVector(IntPtr call, int index, out IntPtr vector);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetOutputCtrlParamVectorName")]
        internal static extern int GetOutputCtrlParamVector(IntPtr call, string name, out IntPtr vector);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetOutputIconicParamObjectIndex")]
        internal static extern int GetOutputIconicParamObject(IntPtr call, int index, out IntPtr key);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetOutputIconicParamObjectName")]
        internal static extern int GetOutputIconicParamObject(IntPtr call, string name, out IntPtr key);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetOutputIconicParamVectorIndex")]
        internal static extern int GetOutputIconicParamVector(IntPtr call, int index, out IntPtr vector);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetOutputIconicParamVectorName")]
        internal static extern int GetOutputIconicParamVector(IntPtr call, string name, out IntPtr vector);

        internal static int CreateObjectVector(HObjectVector inVector, out IntPtr vectorHandle)
        {
            int dimension = inVector.Dimension;
            HCkE(CreateObjectVector(dimension, out var vector_handle));
            HCkE(StoreObjectVector(inVector, vector_handle));
            GC.KeepAlive(inVector);
            vectorHandle = vector_handle;
            return 2;
        }

        internal static int StoreObjectVector(HObjectVector inVector, IntPtr vectorHandle)
        {
            int dimension = inVector.Dimension;
            int length = inVector.Length;
            ResizeObjectVector(vectorHandle, length);
            if (dimension == 1)
            {
                for (int i = 0; i < length; i++)
                {
                    HCkE(SetObjectVectorObject(vectorHandle, i, inVector[i].O.Key));
                }
            }
            else
            {
                for (int j = 0; j < length; j++)
                {
                    HCkE(CreateObjectVector(inVector[j], out var vectorHandle2));
                    HCkE(SetObjectVectorVector(vectorHandle, j, vectorHandle2));
                    HCkE(DestroyObjectVector(vectorHandle2));
                }
            }

            GC.KeepAlive(inVector);
            return 2;
        }

        internal static HObjectVector GetAndDestroyObjectVector(IntPtr vectorHandle)
        {
            HCkE(GetObjectVectorDimension(vectorHandle, out var dimension));
            HObjectVector hObjectVector = new HObjectVector(dimension);
            HCkE(LoadObjectVector(hObjectVector, vectorHandle));
            HCkE(DestroyObjectVector(vectorHandle));
            return hObjectVector;
        }

        internal static int LoadObjectVector(HObjectVector outVector, IntPtr vectorHandle)
        {
            HCkE(GetObjectVectorDimension(vectorHandle, out var dimension));
            HCkE(GetObjectVectorLength(vectorHandle, out var length));
            if (dimension == 1)
            {
                for (int num = length - 1; num >= 0; num--)
                {
                    HCkE(GetObjectVectorObject(vectorHandle, num, out var key));
                    outVector[num].O = new HObject(key, copy: false);
                }
            }
            else
            {
                for (int num2 = length - 1; num2 >= 0; num2--)
                {
                    HCkE(GetObjectVectorVector(vectorHandle, num2, out var sub_vector_handle));
                    HCkE(LoadObjectVector(outVector[num2], sub_vector_handle));
                    HCkE(DestroyObjectVector(sub_vector_handle));
                }
            }

            return 2;
        }

        internal static int CreateTupleVector(HTupleVector inVector, out IntPtr vectorHandle)
        {
            int dimension = inVector.Dimension;
            HCkE(CreateTupleVector(dimension, out var vector_handle));
            HCkE(StoreTupleVector(inVector, vector_handle));
            GC.KeepAlive(inVector);
            vectorHandle = vector_handle;
            return 2;
        }

        internal static int StoreTupleVector(HTupleVector inVector, IntPtr vectorHandle)
        {
            int dimension = inVector.Dimension;
            int length = inVector.Length;
            ResizeTupleVector(vectorHandle, length);
            if (dimension == 1)
            {
                for (int i = 0; i < length; i++)
                {
                    HCkE(HalconAPI.CreateTuple(out var tuple));
                    HalconAPI.StoreTuple(tuple, inVector[i].T);
                    HCkE(SetTupleVectorTuple(vectorHandle, i, tuple));
                    HCkE(HalconAPI.DestroyTuple(tuple));
                }
            }
            else
            {
                for (int j = 0; j < length; j++)
                {
                    HCkE(CreateTupleVector(inVector[j], out var vectorHandle2));
                    HCkE(SetTupleVectorVector(vectorHandle, j, vectorHandle2));
                    HCkE(DestroyTupleVector(vectorHandle2));
                }
            }

            GC.KeepAlive(inVector);
            return 2;
        }

        internal static HTupleVector GetAndDestroyTupleVector(IntPtr vectorHandle)
        {
            HCkE(GetTupleVectorDimension(vectorHandle, out var dimension));
            HTupleVector hTupleVector = new HTupleVector(dimension);
            HCkE(LoadTupleVector(hTupleVector, vectorHandle));
            HCkE(DestroyTupleVector(vectorHandle));
            return hTupleVector;
        }

        internal static int LoadTupleVector(HTupleVector outVector, IntPtr vectorHandle)
        {
            HCkE(GetTupleVectorDimension(vectorHandle, out var dimension));
            HCkE(GetTupleVectorLength(vectorHandle, out var length));
            if (dimension == 1)
            {
                for (int num = length - 1; num >= 0; num--)
                {
                    HCkE(GetTupleVectorTuple(vectorHandle, num, out var element_handle));
                    outVector[num].T = HalconAPI.LoadTuple(element_handle);
                }
            }
            else
            {
                for (int num2 = length - 1; num2 >= 0; num2--)
                {
                    HCkE(GetTupleVectorVector(vectorHandle, num2, out var element_handle2));
                    HCkE(LoadTupleVector(outVector[num2], element_handle2));
                    HCkE(DestroyTupleVector(element_handle2));
                }
            }

            return 2;
        }

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenCreateTupleVector")]
        internal static extern int CreateTupleVector(int dimension, out IntPtr vector_handle);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenDestroyTupleVector")]
        internal static extern int DestroyTupleVector(IntPtr vector_handle);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetTupleVectorDimension")]
        internal static extern int GetTupleVectorDimension(IntPtr vector_handle, out int dimension);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetTupleVectorLength")]
        internal static extern int GetTupleVectorLength(IntPtr vector_handle, out int length);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenResizeTupleVector")]
        internal static extern int ResizeTupleVector(IntPtr vector_handle, int new_size);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetTupleVectorElementVector")]
        internal static extern int SetTupleVectorVector(IntPtr vector_handle, int index, IntPtr element_handle);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetTupleVectorElementTuple")]
        internal static extern int SetTupleVectorTuple(IntPtr vector_handle, int index, IntPtr element_handle);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetTupleVectorElementVector")]
        internal static extern int GetTupleVectorVector(IntPtr vector_handle, int index, out IntPtr element_handle);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetTupleVectorElementTuple")]
        internal static extern int GetTupleVectorTuple(IntPtr vector_handle, int index, out IntPtr element_handle);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenCreateObjectVector")]
        internal static extern int CreateObjectVector(int dimension, out IntPtr vector_handle);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenDestroyObjectVector")]
        internal static extern int DestroyObjectVector(IntPtr vector_handle);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetObjectVectorDimension")]
        internal static extern int GetObjectVectorDimension(IntPtr vector_handle, out int dimension);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetObjectVectorLength")]
        internal static extern int GetObjectVectorLength(IntPtr vector_handle, out int length);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenResizeObjectVector")]
        internal static extern int ResizeObjectVector(IntPtr vector_handle, int new_size);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetObjectVectorElementVector")]
        internal static extern int SetObjectVectorVector(IntPtr vector_handle, int index, IntPtr sub_vector_handle);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenSetObjectVectorElementObject")]
        internal static extern int SetObjectVectorObject(IntPtr vector_handle, int index, IntPtr key);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetObjectVectorElementVector")]
        internal static extern int GetObjectVectorVector(IntPtr vector_handle, int index, out IntPtr sub_vector_handle);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenGetObjectVectorElementObject")]
        internal static extern int GetObjectVectorObject(IntPtr vector_handle, int index, out IntPtr key);

        internal static void AssertObjectClass(IntPtr key, string assertClass, string procedureName)
        {
            if (!(key != HObjectBase.UNDEF))
            {
                return;
            }

            HObject hObject = new HObject(key);
            HTuple objClass = hObject.GetObjClass();
            hObject.Dispose();
            if (objClass.Length > 0)
            {
                string s = objClass.S;
                if (!s.StartsWith(assertClass))
                {
                    HDevEngineException.ThrowGeneric("Output object type mismatch (excepted " + assertClass + ", got " + s + ")", procedureName);
                }
            }
        }

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenCreateImplementation")]
        internal static extern int CreateImplementation(out IntPtr implementation, DevOpenWindowDelegate delegateDevOpenWindow, DevCloseWindowDelegate delegateDevCloseWindow, DevSetWindowDelegate delegateDevSetWindow, DevGetWindowDelegate delegateDevGetWindow, DevSetWindowExtentsDelegate delegateDevSetWindowExtents, DevSetPartDelegate delegateDevSetPart, DevClearWindowDelegate delegateDevClearWindow, DevDisplayDelegate delegateDevDisplay, DevDispTextDelegate delegateDevDispText, DevSetDrawDelegate delegateDevSetDraw, DevSetContourStyleDelegate delegateDevSetContourStyle, DevSetShapeDelegate delegateDevSetShape, DevSetColoredDelegate delegateDevSetColored, DevSetColorDelegate delegateDevSetColor, DevSetLutDelegate delegateDevSetLut, DevSetPaintDelegate delegateDevSetPaint, DevSetLineWidthDelegate delegateDevSetLineWidth);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HCenDestroyImplementation")]
        internal static extern int DestroyImplementation(IntPtr implementation);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl)]
        internal static extern int HCenGetLastException(out int category, out IntPtr message, out IntPtr procedureName, out IntPtr lineText, out int lineNumber, out IntPtr userData);

        [DllImport("hdevenginecppxl", CallingConvention = CallingConvention.Cdecl)]
        internal static extern void HCenReleaseLastException();

        internal static int GetLastException(out int category, out string message, out string procedureName, out string lineText, out int lineNumber, out HTuple userData)
        {
            IntPtr message2;
            IntPtr procedureName2;
            IntPtr lineText2;
            IntPtr userData2;
            int result = HCenGetLastException(out category, out message2, out procedureName2, out lineText2, out lineNumber, out userData2);
            try
            {
                message = Marshal.PtrToStringAnsi(message2);
                procedureName = Marshal.PtrToStringAnsi(procedureName2);
                lineText = Marshal.PtrToStringAnsi(lineText2);
                userData = HalconAPI.LoadTuple(userData2);
            }
            catch
            {
                message = "Error handling exception";
                procedureName = "";
                lineText = "";
                userData = new HTuple();
            }

            HCenReleaseLastException();
            return result;
        }

        internal static void HCkE(int err)
        {
            switch (err)
            {
                default:
                    if (err == 2)
                    {
                        break;
                    }

                    goto case -1;
                case -1:
                    HDevEngineException.ThrowLastException(err);
                    break;
                case 2:
                    break;
            }
        }
    }
    //
    // 摘要:
    //     This is raised when errors occur within HDevEngine
    public class HDevEngine : IDisposable
    {
        private IntPtr engine = IntPtr.Zero;

        private HDevOperatorWrapper operatorWrapper;

        //
        // 摘要:
        //     Creates a new instance of HDevEngine
        public HDevEngine()
        {
            HCkE(EngineAPI.CreateEngine(out engine));
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Returns true if this class has not yet been disposed
        public bool IsInitialized()
        {
            return engine != IntPtr.Zero;
        }

        //
        // 摘要:
        //     Changes a global setting of the engine
        //
        // 参数:
        //   name:
        //     The name of the attribute, e.g. "ignore_invalid_lines" or "ignore_unresolved_lines"
        //
        //   attributeValue:
        //     The new value of the attribute
        public void SetEngineAttribute(string name, HTuple attributeValue)
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HalconAPI.StoreTuple(tuple, attributeValue);
            int err = EngineAPI.SetEngineAttribute(engine, name, tuple);
            GC.KeepAlive(this);
            HalconAPI.DestroyTuple(tuple);
            HCkE(err);
        }

        //
        // 摘要:
        //     Queries a global setting of the engine
        //
        // 参数:
        //   name:
        //     The name of the attribute, e.g. "ignore_invalid_lines" or "ignore_unresolved_lines"
        //
        // 返回结果:
        //     The current value of the attribute
        public HTuple GetEngineAttribute(string name)
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(EngineAPI.GetEngineAttribute(engine, name, tuple));
            GC.KeepAlive(this);
            HTuple result = HalconAPI.LoadTuple(tuple);
            HCkE(HalconAPI.DestroyTuple(tuple));
            return result;
        }

        //
        // 摘要:
        //     Starts the debug server that allows to attach HDevelop as as debugger to step
        //     through engine code.
        //
        // 言论:
        //     With default settings server waits on port 57786 and engine runs normally until
        //     HDevelop is connected and F9 is pressed to stop execution.
        public void StartDebugServer()
        {
            HCkE(EngineAPI.StartDebugServer(engine));
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Stops the debug server (resuming execution if stopped)
        public void StopDebugServer()
        {
            HCkE(EngineAPI.StopDebugServer(engine));
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Sets the path for loading external procedures
        //
        // 参数:
        //   path:
        //     List of directories in the path format of the operating system
        public void SetProcedurePath(string path)
        {
            HCkE(EngineAPI.SetProcedurePath(engine, path));
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Appends to the path for loading external procedures
        //
        // 参数:
        //   path:
        //     List of directories in the path format of the operating system
        public void AddProcedurePath(string path)
        {
            HCkE(EngineAPI.AddProcedurePath(engine, path));
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Returns the names of available procedures
        //
        // 返回结果:
        //     String tuple containing the procedure names
        public HTuple GetProcedureNames()
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(EngineAPI.GetProcedureNames(engine, tuple));
            GC.KeepAlive(this);
            HTuple result = HalconAPI.LoadTuple(tuple);
            HCkE(HalconAPI.DestroyTuple(tuple));
            return result;
        }

        //
        // 摘要:
        //     Returns the names of loaded procedures
        //
        // 返回结果:
        //     String tuple containing the procedure names
        public HTuple GetLoadedProcedureNames()
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(EngineAPI.GetLoadedProcedureNames(engine, tuple));
            GC.KeepAlive(this);
            HTuple result = HalconAPI.LoadTuple(tuple);
            HCkE(HalconAPI.DestroyTuple(tuple));
            return result;
        }

        //
        // 摘要:
        //     Unloads a previously loaded procedure
        //
        // 参数:
        //   name:
        //     The name of the procedure to unload
        public void UnloadProcedure(string name)
        {
            HCkE(EngineAPI.UnloadProcedure(engine, name));
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Unloads all previously loaded procedure
        public void UnloadAllProcedures()
        {
            HCkE(EngineAPI.UnloadAllProcedures(engine));
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Returns the names of all global iconic variables
        public HTuple GetGlobalIconicVarNames()
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(EngineAPI.GetGlobalIconicVarNames(engine, tuple));
            GC.KeepAlive(this);
            HTuple result = HalconAPI.LoadTuple(tuple);
            HCkE(HalconAPI.DestroyTuple(tuple));
            return result;
        }

        //
        // 摘要:
        //     Returns the names of all global control variables
        public HTuple GetGlobalCtrlVarNames()
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(EngineAPI.GetGlobalCtrlVarNames(engine, tuple));
            GC.KeepAlive(this);
            HTuple result = HalconAPI.LoadTuple(tuple);
            HCkE(HalconAPI.DestroyTuple(tuple));
            return result;
        }

        //
        // 摘要:
        //     Gets the dimension of a global control variable
        public int GetGlobalIconicVarDimension(string name)
        {
            HCkE(EngineAPI.GetGlobalIconicVarDimension(engine, name, out var dimension));
            GC.KeepAlive(this);
            return dimension;
        }

        //
        // 摘要:
        //     Gets the dimension of a global control variable
        public int GetGlobalCtrlVarDimension(string name)
        {
            HCkE(EngineAPI.GetGlobalCtrlVarDimension(engine, name, out var dimension));
            GC.KeepAlive(this);
            return dimension;
        }

        //
        // 摘要:
        //     Sets the value of a global control variable
        public void SetGlobalCtrlVarTuple(string name, HTuple tuple)
        {
            HCkE(HalconAPI.CreateTuple(out var tuple2));
            HalconAPI.StoreTuple(tuple2, tuple);
            HCkE(EngineAPI.SetGlobalCtrlVarTuple(engine, name, tuple2));
            GC.KeepAlive(this);
            HCkE(HalconAPI.DestroyTuple(tuple2));
        }

        //
        // 摘要:
        //     Sets the value of a global control variable
        public void SetGlobalCtrlVarVector(string name, HTupleVector vector)
        {
            HCkE(EngineAPI.CreateTupleVector(vector, out var vectorHandle));
            HCkE(EngineAPI.SetGlobalCtrlVarVector(engine, name, vectorHandle));
            GC.KeepAlive(this);
            HCkE(EngineAPI.DestroyTupleVector(vectorHandle));
        }

        //
        // 摘要:
        //     Sets the value of a global iconic variable
        public void SetGlobalIconicVarObject(string name, HObject iconic)
        {
            HCkE(EngineAPI.SetGlobalIconicVarObject(engine, name, iconic.Key));
            GC.KeepAlive(iconic);
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Sets the value of a global iconic variable
        public void SetGlobalIconicVarVector(string name, HObjectVector vector)
        {
            HCkE(EngineAPI.CreateObjectVector(vector, out var vectorHandle));
            HCkE(EngineAPI.SetGlobalIconicVarVector(engine, name, vectorHandle));
            GC.KeepAlive(this);
            HCkE(EngineAPI.DestroyObjectVector(vectorHandle));
        }

        //
        // 摘要:
        //     Gets the value of a global control variable
        public HTuple GetGlobalCtrlVarTuple(string name)
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(EngineAPI.GetGlobalCtrlVarTuple(engine, name, tuple));
            GC.KeepAlive(this);
            HTuple result = HalconAPI.LoadTuple(tuple);
            HCkE(HalconAPI.DestroyTuple(tuple));
            return result;
        }

        //
        // 摘要:
        //     Gets the value of a global control variable
        public HTupleVector GetGlobalCtrlVarVector(string name)
        {
            HCkE(EngineAPI.GetGlobalCtrlVarVector(engine, name, out var vector));
            GC.KeepAlive(this);
            return EngineAPI.GetAndDestroyTupleVector(vector);
        }

        //
        // 摘要:
        //     Gets the value of a global iconic variable
        public HObject GetGlobalIconicVarObject(string name)
        {
            HCkE(EngineAPI.GetGlobalIconicVarObject(engine, name, out var key));
            GC.KeepAlive(this);
            return new HObject(key, copy: false);
        }

        //
        // 摘要:
        //     Gets the value of a global iconic variable
        public HObjectVector GetGlobalIconicVarVector(string name)
        {
            HCkE(EngineAPI.GetGlobalIconicVarVector(engine, name, out var vector));
            GC.KeepAlive(this);
            return EngineAPI.GetAndDestroyObjectVector(vector);
        }

        //
        // 摘要:
        //     Gets the value of a global iconic image variable
        public HImage GetGlobalIconicVarImage(string name)
        {
            HCkE(EngineAPI.GetGlobalIconicVarObject(engine, name, out var key));
            GC.KeepAlive(this);
            EngineAPI.AssertObjectClass(key, "image", "main");
            return new HImage(key, copy: false);
        }

        //
        // 摘要:
        //     Gets the value of a global iconic region variable
        public HRegion GetGlobalIconicVarRegion(string name)
        {
            HCkE(EngineAPI.GetGlobalIconicVarObject(engine, name, out var key));
            GC.KeepAlive(this);
            EngineAPI.AssertObjectClass(key, "region", "main");
            return new HRegion(key, copy: false);
        }

        //
        // 摘要:
        //     Gets the value of a global iconic XLD variable
        public HXLD GetGlobalIconicVarXld(string name)
        {
            HCkE(EngineAPI.GetGlobalIconicVarObject(engine, name, out var key));
            GC.KeepAlive(this);
            EngineAPI.AssertObjectClass(key, "xld", "main");
            return new HXLD(key, copy: false);
        }

        //
        // 摘要:
        //     Registers your implementation of visualization operators
        //
        // 参数:
        //   implementation:
        //     An object implementing the IHDevOperators interface
        public void SetHDevOperators(IHDevOperators implementation)
        {
            if (implementation == null)
            {
                HCkE(EngineAPI.SetHDevOperatorImpl(engine, IntPtr.Zero));
                GC.KeepAlive(this);
                operatorWrapper = null;
            }
            else
            {
                operatorWrapper = new HDevOperatorWrapper(this, implementation);
                HCkE(EngineAPI.SetHDevOperatorImpl(engine, operatorWrapper.ImplementationHandle));
                GC.KeepAlive(this);
            }
        }

        internal static void HCkE(int err)
        {
            EngineAPI.HCkE(err);
        }

        ~HDevEngine()
        {
            try
            {
                Dispose();
            }
            catch (Exception)
            {
            }
        }

        void IDisposable.Dispose()
        {
            Dispose();
        }

        //
        // 摘要:
        //     Releases the resources used by this engine
        public virtual void Dispose()
        {
            if (engine != IntPtr.Zero)
            {
                EngineAPI.DestroyEngine(engine);
                engine = IntPtr.Zero;
            }

            GC.SuppressFinalize(this);
            GC.KeepAlive(this);
        }
    }

    public class HDevEngineException : HalconException
    {
        //
        // 摘要:
        //     Different types of errors when using HDevEngine
        public enum ExceptionCategory
        {
            //
            // 摘要:
            //     No special type
            Generic,
            //
            // 摘要:
            //     Unintialized input parameters for procedure call
            Input,
            //
            // 摘要:
            //     HALCON error while executing an operator
            Operator,
            //
            // 摘要:
            //     Problems loading scripts or procedures files
            File
        }

        private int halconError;

        private ExceptionCategory category;

        private string procedureName;

        private string lineText;

        private int lineNumber;

        private HTuple userData;

        //
        // 摘要:
        //     The internal HALCON error code
        public int HalconError => halconError;

        //
        // 摘要:
        //     Type of exception
        public ExceptionCategory Category => category;

        //
        // 摘要:
        //     Name of the originating HDevelop procedure
        public string ProcedureName => procedureName;

        //
        // 摘要:
        //     Script line in which the error occured
        public string LineText => lineText;

        //
        // 摘要:
        //     Script line number at which the error occured
        public int LineNumber => lineNumber;

        //
        // 摘要:
        //     User data which was added to the exception
        public HTuple UserData => userData;

        internal static void ThrowGeneric(string message)
        {
            ThrowGeneric(message, "");
        }

        internal static void ThrowGeneric(string message, string procedureName)
        {
            throw new HDevEngineException(2, ExceptionCategory.Generic, message, procedureName, "", 0, new HTuple());
        }

        internal static void ThrowLastException(int err)
        {
            int num;
            string message;
            string text;
            string text2;
            int num2;
            HTuple hTuple;
            int lastException = EngineAPI.GetLastException(out num, out message, out text, out text2, out num2, out hTuple);
            if (err != -1 && lastException == 2)
            {
                throw new HOperatorException(err);
            }

            throw new HDevEngineException(lastException, (ExceptionCategory)num, message, text, text2, num2, hTuple);
        }

        internal HDevEngineException(int halconError, ExceptionCategory category, string message, string procedureName, string lineText, int lineNumber, HTuple userData)
            : base(message)
        {
            this.halconError = halconError;
            this.category = category;
            this.procedureName = procedureName;
            this.lineText = lineText;
            this.lineNumber = lineNumber;
            this.userData = userData;
        }

        public override string ToString()
        {
            string text = "HDevEngine: " + Message;
            if (procedureName != "")
            {
                text = text + " in " + procedureName;
            }

            if (lineNumber > 0)
            {
                object obj = text;
                text = string.Concat(obj, " at line ", lineNumber, " (", lineText, ")");
            }

            return text;
        }
    }


    //
    // 摘要:
    //     This class wraps an object implementing IHDevOperators, registers internal delegates
    //     with the HDevEngine and calls the appropriate interface methods at callback time
    //     (including conversion of parameters and transformation of exceptions to return
    //     codes).
    internal class HDevOperatorWrapper
    {
        private IntPtr implHandle = IntPtr.Zero;

        private IHDevOperators implementation;

        private DevOpenWindowDelegate delegateDevOpenWindow;

        private DevCloseWindowDelegate delegateDevCloseWindow;

        private DevSetWindowDelegate delegateDevSetWindow;

        private DevGetWindowDelegate delegateDevGetWindow;

        private DevSetWindowExtentsDelegate delegateDevSetWindowExtents;

        private DevSetPartDelegate delegateDevSetPart;

        private DevClearWindowDelegate delegateDevClearWindow;

        private DevDisplayDelegate delegateDevDisplay;

        private DevDispTextDelegate delegateDevDispText;

        private DevSetDrawDelegate delegateDevSetDraw;

        private DevSetContourStyleDelegate delegateDevSetContourStyle;

        private DevSetShapeDelegate delegateDevSetShape;

        private DevSetColoredDelegate delegateDevSetColored;

        private DevSetColorDelegate delegateDevSetColor;

        private DevSetLutDelegate delegateDevSetLut;

        private DevSetPaintDelegate delegateDevSetPaint;

        private DevSetLineWidthDelegate delegateDevSetLineWidth;

        public IntPtr ImplementationHandle => implHandle;

        public HDevOperatorWrapper(HDevEngine engine, IHDevOperators implementation)
        {
            this.implementation = implementation;
            delegateDevOpenWindow = DevOpenWindow;
            delegateDevCloseWindow = DevCloseWindow;
            delegateDevSetWindow = DevSetWindow;
            delegateDevGetWindow = DevGetWindow;
            delegateDevSetWindowExtents = DevSetWindowExtents;
            delegateDevSetPart = DevSetPart;
            delegateDevClearWindow = DevClearWindow;
            delegateDevDisplay = DevDisplay;
            delegateDevDispText = DevDispText;
            delegateDevSetDraw = DevSetDraw;
            delegateDevSetContourStyle = DevSetContourStyle;
            delegateDevSetShape = DevSetShape;
            delegateDevSetColored = DevSetColored;
            delegateDevSetColor = DevSetColor;
            delegateDevSetLut = DevSetLut;
            delegateDevSetPaint = DevSetPaint;
            delegateDevSetLineWidth = DevSetLineWidth;
            EngineAPI.HCkE(EngineAPI.CreateImplementation(out implHandle, delegateDevOpenWindow, delegateDevCloseWindow, delegateDevSetWindow, delegateDevGetWindow, delegateDevSetWindowExtents, delegateDevSetPart, delegateDevClearWindow, delegateDevDisplay, delegateDevDispText, delegateDevSetDraw, delegateDevSetContourStyle, delegateDevSetShape, delegateDevSetColored, delegateDevSetColor, delegateDevSetLut, delegateDevSetPaint, delegateDevSetLineWidth));
            GC.KeepAlive(this);
        }

        private static HTuple LoadTuple(IntPtr tupleHandle)
        {
            return HalconAPI.LoadTuple(tupleHandle);
        }

        private static int ToHalconError(Exception e)
        {
            if (e is HOperatorException)
            {
                return ((HOperatorException)e).GetErrorCode();
            }

            if (e is HDevEngineException)
            {
                return ((HDevEngineException)e).HalconError;
            }

            return 5;
        }

        private int DevOpenWindow(IntPtr row, IntPtr column, IntPtr width, IntPtr height, IntPtr background, IntPtr windowID)
        {
            try
            {
                implementation.DevOpenWindow(LoadTuple(row), LoadTuple(column), LoadTuple(width), LoadTuple(height), LoadTuple(background), out var windowHandle);
                HalconAPI.StoreTuple(windowID, windowHandle);
                windowHandle.Dispose();
            }
            catch (Exception e)
            {
                return ToHalconError(e);
            }

            return 2;
        }

        private int DevCloseWindow()
        {
            try
            {
                implementation.DevCloseWindow();
            }
            catch (Exception e)
            {
                return ToHalconError(e);
            }

            return 2;
        }

        private int DevSetWindow(IntPtr windowID)
        {
            try
            {
                HTuple hTuple = LoadTuple(windowID);
                implementation.DevSetWindow(hTuple);
                hTuple.Dispose();
            }
            catch (Exception e)
            {
                return ToHalconError(e);
            }

            return 2;
        }

        private int DevGetWindow(IntPtr windowID)
        {
            try
            {
                implementation.DevGetWindow(out var windowHandle);
                HalconAPI.StoreTuple(windowID, windowHandle);
                windowHandle.Dispose();
            }
            catch (Exception e)
            {
                return ToHalconError(e);
            }

            return 2;
        }

        private int DevSetWindowExtents(IntPtr row, IntPtr column, IntPtr width, IntPtr height)
        {
            try
            {
                implementation.DevSetWindowExtents(LoadTuple(row), LoadTuple(column), LoadTuple(width), LoadTuple(height));
            }
            catch (Exception e)
            {
                return ToHalconError(e);
            }

            return 2;
        }

        private int DevSetPart(IntPtr row, IntPtr column, IntPtr width, IntPtr height)
        {
            try
            {
                implementation.DevSetPart(LoadTuple(row), LoadTuple(column), LoadTuple(width), LoadTuple(height));
            }
            catch (Exception e)
            {
                return ToHalconError(e);
            }

            return 2;
        }

        private int DevClearWindow()
        {
            try
            {
                implementation.DevClearWindow();
            }
            catch (Exception e)
            {
                return ToHalconError(e);
            }

            return 2;
        }

        private int DevDisplay(IntPtr key)
        {
            HObject hObject = null;
            try
            {
                hObject = new HObject(key);
                implementation.DevDisplay(hObject);
                hObject.Dispose();
            }
            catch (Exception e)
            {
                hObject?.Dispose();
                return ToHalconError(e);
            }

            return 2;
        }

        private int DevDispText(IntPtr text, IntPtr coordSystem, IntPtr row, IntPtr column, IntPtr color, IntPtr genParamNames, IntPtr genParamValues)
        {
            try
            {
                implementation.DevDispText(LoadTuple(text), LoadTuple(coordSystem), LoadTuple(row), LoadTuple(column), LoadTuple(color), LoadTuple(genParamNames), LoadTuple(genParamValues));
            }
            catch (Exception e)
            {
                return ToHalconError(e);
            }

            return 2;
        }

        private int DevSetDraw(IntPtr draw)
        {
            try
            {
                implementation.DevSetDraw(LoadTuple(draw));
            }
            catch (Exception e)
            {
                return ToHalconError(e);
            }

            return 2;
        }

        private int DevSetContourStyle(IntPtr style)
        {
            try
            {
                implementation.DevSetContourStyle(LoadTuple(style));
            }
            catch (Exception e)
            {
                return ToHalconError(e);
            }

            return 2;
        }

        private int DevSetShape(IntPtr shape)
        {
            try
            {
                implementation.DevSetShape(LoadTuple(shape));
            }
            catch (Exception e)
            {
                return ToHalconError(e);
            }

            return 2;
        }

        private int DevSetColored(IntPtr colored)
        {
            try
            {
                implementation.DevSetColored(LoadTuple(colored));
            }
            catch (Exception e)
            {
                return ToHalconError(e);
            }

            return 2;
        }

        private int DevSetColor(IntPtr color)
        {
            try
            {
                implementation.DevSetColor(LoadTuple(color));
            }
            catch (Exception e)
            {
                return ToHalconError(e);
            }

            return 2;
        }

        private int DevSetLut(IntPtr lut)
        {
            try
            {
                implementation.DevSetLut(LoadTuple(lut));
            }
            catch (Exception e)
            {
                return ToHalconError(e);
            }

            return 2;
        }

        private int DevSetPaint(IntPtr paint)
        {
            try
            {
                implementation.DevSetPaint(LoadTuple(paint));
            }
            catch (Exception e)
            {
                return ToHalconError(e);
            }

            return 2;
        }

        private int DevSetLineWidth(IntPtr width)
        {
            try
            {
                implementation.DevSetLineWidth(LoadTuple(width));
            }
            catch (Exception e)
            {
                return ToHalconError(e);
            }

            return 2;
        }

        ~HDevOperatorWrapper()
        {
            try
            {
                if (implHandle != IntPtr.Zero)
                {
                    EngineAPI.DestroyImplementation(implHandle);
                    GC.KeepAlive(this);
                }
            }
            catch (Exception)
            {
            }
        }
    }

    public class HDevProcedure : IDisposable
    {
        private IntPtr procedure = IntPtr.Zero;

        private string name = "";

        private string shortDescription = "";

        private bool loaded;

        private HTuple parNamesIconicInput = new HTuple();

        private HTuple parNamesIconicOutput = new HTuple();

        private HTuple parNamesCtrlInput = new HTuple();

        private HTuple parNamesCtrlOutput = new HTuple();

        private HTuple parDimensionsIconicInput = new HTuple();

        private HTuple parDimensionsIconicOutput = new HTuple();

        private HTuple parDimensionsCtrlInput = new HTuple();

        private HTuple parDimensionsCtrlOutput = new HTuple();

        internal IntPtr Handle => procedure;

        //
        // 摘要:
        //     The name of the procedure
        public string Name => name;

        //
        // 摘要:
        //     The short description of the procedure
        public string ShortDescription => shortDescription;

        //
        // 摘要:
        //     Creates an empty procedure instance
        public HDevProcedure()
        {
            HCkE(EngineAPI.CreateProcedure(out procedure));
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Loads an external procedure
        public HDevProcedure(string procedureName)
            : this()
        {
            LoadProcedure(procedureName);
        }

        //
        // 摘要:
        //     Loads a local procedure
        public HDevProcedure(string programName, string procedureName)
            : this()
        {
            LoadProcedure(programName, procedureName);
        }

        //
        // 摘要:
        //     Loads a local procedure
        public HDevProcedure(HDevProgram program, string procedureName)
            : this()
        {
            LoadProcedure(program, procedureName);
        }

        internal void UpdateProcedureInfo()
        {
            EngineAPI.GetProcedureInfo(procedure, out name, out shortDescription, out loaded, out parNamesIconicInput, out parNamesIconicOutput, out parNamesCtrlInput, out parNamesCtrlOutput, out parDimensionsIconicInput, out parDimensionsIconicOutput, out parDimensionsCtrlInput, out parDimensionsCtrlOutput);
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Loads an external procedure
        public void LoadProcedure(string procedureName)
        {
            HCkE(EngineAPI.LoadProcedure(procedure, procedureName));
            GC.KeepAlive(this);
            UpdateProcedureInfo();
        }

        //
        // 摘要:
        //     Loads a local procedure
        public void LoadProcedure(string programName, string procedureName)
        {
            HCkE(EngineAPI.LoadProcedure(procedure, programName, procedureName));
            GC.KeepAlive(this);
            UpdateProcedureInfo();
        }

        //
        // 摘要:
        //     Loads a local procedure
        public void LoadProcedure(HDevProgram program, string procedureName)
        {
            if (program.Handle == IntPtr.Zero)
            {
                HDevEngineException.ThrowGeneric("Uninitialized program while creating a local procedure call");
            }

            HCkE(EngineAPI.LoadProcedure(procedure, program.Handle, procedureName));
            GC.KeepAlive(this);
            UpdateProcedureInfo();
        }

        //
        // 摘要:
        //     Creates a procedure call for this procedure
        public HDevProcedureCall CreateCall()
        {
            return new HDevProcedureCall(this);
        }

        //
        // 摘要:
        //     Create and execute a procedure call for this procedure
        public HDevProcedureCall Execute()
        {
            HDevProcedureCall hDevProcedureCall = new HDevProcedureCall(this);
            hDevProcedureCall.Execute();
            return hDevProcedureCall;
        }

        //
        // 摘要:
        //     Check the load state of the procedure
        public bool IsLoaded()
        {
            return loaded;
        }

        //
        // 摘要:
        //     Returns true if this class has not yet been disposed
        public bool IsInitialized()
        {
            return procedure != IntPtr.Zero;
        }

        //
        // 摘要:
        //     Gets the names of the iconic input parameters
        public HTuple GetInputIconicParamNames()
        {
            return parNamesIconicInput.Clone();
        }

        //
        // 摘要:
        //     Gets the names of the iconic output parameters
        public HTuple GetOutputIconicParamNames()
        {
            return parNamesIconicOutput.Clone();
        }

        //
        // 摘要:
        //     Gets the names of the input control parameters
        public HTuple GetInputCtrlParamNames()
        {
            return parNamesCtrlInput.Clone();
        }

        //
        // 摘要:
        //     Gets the names of the output control parameters
        public HTuple GetOutputCtrlParamNames()
        {
            return parNamesCtrlOutput.Clone();
        }

        //
        // 摘要:
        //     Gets the dimensions of the iconic input parameters
        public HTuple GetInputIconicParamDimensions()
        {
            return parDimensionsIconicInput.Clone();
        }

        //
        // 摘要:
        //     Gets the dimensions of the iconic output parameters
        public HTuple GetOutputIconicParamDimensions()
        {
            return parDimensionsIconicOutput.Clone();
        }

        //
        // 摘要:
        //     Gets the dimensions of the input control parameters
        public HTuple GetInputCtrlParamDimensions()
        {
            return parDimensionsCtrlInput.Clone();
        }

        //
        // 摘要:
        //     Gets the dimensions of the output control parameters
        public HTuple GetOutputCtrlParamDimensions()
        {
            return parDimensionsCtrlOutput.Clone();
        }

        //
        // 摘要:
        //     Gets the number of parameters used for iconic input objects. Note that parameters
        //     are numbered from 1 to count.
        public int GetInputIconicParamCount()
        {
            return parNamesIconicInput.Length;
        }

        //
        // 摘要:
        //     Gets the number of parameters used for iconic output objects. Note that parameters
        //     are numbered from 1 to count.
        public int GetOutputIconicParamCount()
        {
            return parNamesIconicOutput.Length;
        }

        //
        // 摘要:
        //     Gets the number of parameters used for input control values. Note that parameters
        //     are numbered from 1 to count.
        public int GetInputCtrlParamCount()
        {
            return parNamesCtrlInput.Length;
        }

        //
        // 摘要:
        //     Gets the number of parameters used for output control values. Note that parameters
        //     are numbered from 1 to count.
        public int GetOutputCtrlParamCount()
        {
            return parNamesCtrlOutput.Length;
        }

        //
        // 摘要:
        //     Gets the name of a specific iconic input parameter
        public string GetInputIconicParamName(int index)
        {
            if (index < 1 || index > parNamesIconicInput.Length)
            {
                HDevEngineException.ThrowGeneric("Bad index for GetInputIconicParamName");
            }

            return parNamesIconicInput.SArr[index - 1];
        }

        //
        // 摘要:
        //     Gets the name of a specific iconic output parameter
        public string GetOutputIconicParamName(int index)
        {
            if (index < 1 || index > parNamesIconicOutput.Length)
            {
                HDevEngineException.ThrowGeneric("Bad index for GetOutputIconicParamName");
            }

            return parNamesIconicOutput.SArr[index - 1];
        }

        //
        // 摘要:
        //     Gets the name of a specific input control parameter
        public string GetInputCtrlParamName(int index)
        {
            if (index < 1 || index > parNamesCtrlInput.Length)
            {
                HDevEngineException.ThrowGeneric("Bad index for GetInputCtrlParamName");
            }

            return parNamesCtrlInput.SArr[index - 1];
        }

        //
        // 摘要:
        //     Gets the name of a specific output control parameter
        public string GetOutputCtrlParamName(int index)
        {
            if (index < 1 || index > parNamesCtrlOutput.Length)
            {
                HDevEngineException.ThrowGeneric("Bad index for GetOutputCtrlParamName");
            }

            return parNamesCtrlOutput.SArr[index - 1];
        }

        //
        // 摘要:
        //     Gets the dimension of a specific iconic input parameter
        public int GetInputIconicParamDimension(int index)
        {
            if (index < 1 || index > parDimensionsIconicInput.Length)
            {
                HDevEngineException.ThrowGeneric("Bad index for GetInputIconicParamDimension");
            }

            return parDimensionsIconicInput[index - 1];
        }

        //
        // 摘要:
        //     Gets the dimension of a specific iconic output parameter
        public int GetOutputIconicParamDimension(int index)
        {
            if (index < 1 || index > parDimensionsIconicOutput.Length)
            {
                HDevEngineException.ThrowGeneric("Bad index for GetOutputIconicParamDimension");
            }

            return parDimensionsIconicOutput[index - 1];
        }

        //
        // 摘要:
        //     Gets the dimension of a specific input control parameter
        public int GetInputCtrlParamDimension(int index)
        {
            if (index < 1 || index > parDimensionsCtrlInput.Length)
            {
                HDevEngineException.ThrowGeneric("Bad index for GetInputCtrlParamDimension");
            }

            return parDimensionsCtrlInput[index - 1];
        }

        //
        // 摘要:
        //     Gets the dimension of a specific output control parameter
        public int GetOutputCtrlParamDimension(int index)
        {
            if (index < 1 || index > parDimensionsCtrlOutput.Length)
            {
                HDevEngineException.ThrowGeneric("Bad index for GetOutputCtrlParamDimension");
            }

            return parDimensionsCtrlOutput[index - 1];
        }

        //
        // 摘要:
        //     Returns the names of all refered procedures
        public HTuple GetUsedProcedureNames()
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(EngineAPI.GetUsedProcedureNamesForProcedure(procedure, tuple));
            GC.KeepAlive(this);
            HTuple result = HalconAPI.LoadTuple(tuple);
            HCkE(HalconAPI.DestroyTuple(tuple));
            return result;
        }

        //
        // 摘要:
        //     Compile all procedures that are used by the program and that can be compiled
        //     with a just-in-time compiler. The method returns true when all used procedures
        //     could be compiled by the just-in-time compiler. Procedures that could not be
        //     compiled are called normally by the HDevEngine interpreter. To check which procedure
        //     could not be compiled and what the reason is for that start HDevelop and check
        //     there the compilation states.
        public bool CompileUsedProcedures()
        {
            HCkE(EngineAPI.CompileUsedProceduresForProcedure(procedure, out var ret));
            GC.KeepAlive(this);
            return ret;
        }

        //
        // 摘要:
        //     Returns the info of the refered procedure docu slot
        public HTuple GetInfo(string slot)
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(EngineAPI.GetProcInfo(procedure, slot, tuple));
            GC.KeepAlive(this);
            HTuple result = HalconAPI.LoadTuple(tuple);
            HCkE(HalconAPI.DestroyTuple(tuple));
            return result;
        }

        //
        // 摘要:
        //     Returns the info of the refered parameter docu slot
        public HTuple GetParamInfo(string parName, string slot)
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(EngineAPI.GetParamInfo(procedure, parName, slot, tuple));
            GC.KeepAlive(this);
            HTuple result = HalconAPI.LoadTuple(tuple);
            HCkE(HalconAPI.DestroyTuple(tuple));
            return result;
        }

        //
        // 摘要:
        //     Returns the info of the refered parameter docu slot
        public HTuple GetInputIconicParamInfo(int parIdx, string slot)
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(EngineAPI.GetInputIconicParamInfo(procedure, parIdx, slot, tuple));
            GC.KeepAlive(this);
            HTuple result = HalconAPI.LoadTuple(tuple);
            HCkE(HalconAPI.DestroyTuple(tuple));
            return result;
        }

        //
        // 摘要:
        //     Returns the info of the refered parameter docu slot
        public HTuple GetOutputIconicParamInfo(int parIdx, string slot)
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(EngineAPI.GetOutputIconicParamInfo(procedure, parIdx, slot, tuple));
            GC.KeepAlive(this);
            HTuple result = HalconAPI.LoadTuple(tuple);
            HCkE(HalconAPI.DestroyTuple(tuple));
            return result;
        }

        //
        // 摘要:
        //     Returns the info of the refered parameter docu slot
        public HTuple GetInputCtrlParamInfo(int parIdx, string slot)
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(EngineAPI.GetInputCtrlParamInfo(procedure, parIdx, slot, tuple));
            GC.KeepAlive(this);
            HTuple result = HalconAPI.LoadTuple(tuple);
            HCkE(HalconAPI.DestroyTuple(tuple));
            return result;
        }

        //
        // 摘要:
        //     Returns the info of the refered parameter docu slot
        public HTuple GetOutputCtrlParamInfo(int parIdx, string slot)
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(EngineAPI.GetOutputCtrlParamInfo(procedure, parIdx, slot, tuple));
            GC.KeepAlive(this);
            HTuple result = HalconAPI.LoadTuple(tuple);
            HCkE(HalconAPI.DestroyTuple(tuple));
            return result;
        }

        //
        // 摘要:
        //     Returns all possible slots of the procedure docu
        public HTuple QueryInfo()
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(EngineAPI.QueryInfo(procedure, tuple));
            GC.KeepAlive(this);
            HTuple result = HalconAPI.LoadTuple(tuple);
            HCkE(HalconAPI.DestroyTuple(tuple));
            return result;
        }

        //
        // 摘要:
        //     Returns all possible slots of the parameter docu
        public HTuple QueryParamInfo()
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(EngineAPI.QueryParamInfo(procedure, tuple));
            GC.KeepAlive(this);
            HTuple result = HalconAPI.LoadTuple(tuple);
            HCkE(HalconAPI.DestroyTuple(tuple));
            return result;
        }

        internal static void HCkE(int err)
        {
            EngineAPI.HCkE(err);
        }

        ~HDevProcedure()
        {
            try
            {
                Dispose();
            }
            catch (Exception)
            {
            }
        }

        void IDisposable.Dispose()
        {
            Dispose();
        }

        //
        // 摘要:
        //     Releases the resources used by this engine
        public virtual void Dispose()
        {
            if (procedure != IntPtr.Zero)
            {
                EngineAPI.DestroyProcedure(procedure);
                procedure = IntPtr.Zero;
                loaded = false;
            }

            GC.SuppressFinalize(this);
            GC.KeepAlive(this);
        }
    }
    //
    // 摘要:
    //     Manages an execution instance for a local or external procedure
    public class HDevProcedureCall : IDisposable
    {
        private IntPtr call = IntPtr.Zero;

        private HDevProcedure procedure;

        //
        // 摘要:
        //     Creates a procedure call for the specified procedure
        public HDevProcedureCall(HDevProcedure procedure)
        {
            HCkE(EngineAPI.CreateProcedureCall(procedure.Handle, out call));
            GC.KeepAlive(this);
            this.procedure = procedure;
        }

        //
        // 摘要:
        //     Returns true if this class has not yet been disposed
        public bool IsInitialized()
        {
            return call != IntPtr.Zero;
        }

        //
        // 摘要:
        //     Gets the procedure associated with this procedure call
        public HDevProcedure GetProcedure()
        {
            return procedure;
        }

        //
        // 摘要:
        //     Executes the procedure
        public void Execute()
        {
            HCkE(EngineAPI.ExecuteProcedureCall(call));
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Stops execution on first line of procedure.
        //
        // 言论:
        //     This is intended for debugging purposes when you wish to step through a specific
        //     procedure call. It only has an effect when a debug server is running and it will
        //     only stop once.
        public void SetWaitForDebugConnection(bool wait_once)
        {
            HCkE(EngineAPI.SetWaitForDebugConnectionProcedureCall(call, wait_once));
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Resets the procedure execution
        public void Reset()
        {
            HCkE(EngineAPI.ResetProcedureCall(call));
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Sets input control parameter for procedure call
        public void SetInputCtrlParamTuple(int index, HTuple tuple)
        {
            HCkE(HalconAPI.CreateTuple(out var tuple2));
            HalconAPI.StoreTuple(tuple2, tuple);
            HCkE(EngineAPI.SetInputCtrlParamTuple(call, index, tuple2));
            GC.KeepAlive(this);
            HCkE(HalconAPI.DestroyTuple(tuple2));
        }

        //
        // 摘要:
        //     Sets input control parameter for procedure call
        public void SetInputCtrlParamTuple(string name, HTuple tuple)
        {
            HCkE(HalconAPI.CreateTuple(out var tuple2));
            HalconAPI.StoreTuple(tuple2, tuple);
            HCkE(EngineAPI.SetInputCtrlParamTuple(call, name, tuple2));
            GC.KeepAlive(this);
            HCkE(HalconAPI.DestroyTuple(tuple2));
        }

        //
        // 摘要:
        //     Sets input control parameter for procedure call
        public void SetInputCtrlParamVector(int index, HTupleVector vector)
        {
            HCkE(EngineAPI.CreateTupleVector(vector, out var vectorHandle));
            HCkE(EngineAPI.SetInputCtrlParamVector(call, index, vectorHandle));
            GC.KeepAlive(this);
            HCkE(EngineAPI.DestroyTupleVector(vectorHandle));
        }

        //
        // 摘要:
        //     Sets input control parameter for procedure call
        public void SetInputCtrlParamVector(string name, HTupleVector vector)
        {
            HCkE(EngineAPI.CreateTupleVector(vector, out var vectorHandle));
            HCkE(EngineAPI.SetInputCtrlParamVector(call, name, vectorHandle));
            GC.KeepAlive(this);
            HCkE(EngineAPI.DestroyTupleVector(vectorHandle));
        }

        //
        // 摘要:
        //     Sets iconic input object for procedure call
        public void SetInputIconicParamObject(int index, HObject iconic)
        {
            HCkE(EngineAPI.SetInputIconicParamObject(call, index, iconic.Key));
            GC.KeepAlive(iconic);
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Sets iconic input object for procedure call
        public void SetInputIconicParamObject(string name, HObject iconic)
        {
            HCkE(EngineAPI.SetInputIconicParamObject(call, name, iconic.Key));
            GC.KeepAlive(iconic);
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Sets input control parameter for procedure call
        public void SetInputIconicParamVector(int index, HObjectVector vector)
        {
            HCkE(EngineAPI.CreateObjectVector(vector, out var vectorHandle));
            HCkE(EngineAPI.SetInputIconicParamVector(call, index, vectorHandle));
            GC.KeepAlive(this);
            HCkE(EngineAPI.DestroyObjectVector(vectorHandle));
        }

        //
        // 摘要:
        //     Sets input control parameter for procedure call
        public void SetInputIconicParamVector(string name, HObjectVector vector)
        {
            HCkE(EngineAPI.CreateObjectVector(vector, out var vectorHandle));
            HCkE(EngineAPI.SetInputIconicParamVector(call, name, vectorHandle));
            GC.KeepAlive(this);
            HCkE(EngineAPI.DestroyObjectVector(vectorHandle));
        }

        //
        // 摘要:
        //     Gets the value of an output control parameter
        public HTuple GetOutputCtrlParamTuple(int index)
        {
            HCkE(EngineAPI.GetOutputCtrlParamTuple(call, index, out var tuple));
            GC.KeepAlive(this);
            return HalconAPI.LoadTuple(tuple);
        }

        //
        // 摘要:
        //     Gets the value of an output control parameter
        public HTuple GetOutputCtrlParamTuple(string name)
        {
            HCkE(EngineAPI.GetOutputCtrlParamTuple(call, name, out var tuple));
            GC.KeepAlive(this);
            return HalconAPI.LoadTuple(tuple);
        }

        //
        // 摘要:
        //     Gets the value of an output control parameter
        public HTupleVector GetOutputCtrlParamVector(int index)
        {
            HCkE(EngineAPI.GetOutputCtrlParamVector(call, index, out var vector));
            GC.KeepAlive(this);
            return EngineAPI.GetAndDestroyTupleVector(vector);
        }

        //
        // 摘要:
        //     Gets the value of an output control parameter
        public HTupleVector GetOutputCtrlParamVector(string name)
        {
            HCkE(EngineAPI.GetOutputCtrlParamVector(call, name, out var vector));
            GC.KeepAlive(this);
            return EngineAPI.GetAndDestroyTupleVector(vector);
        }

        //
        // 摘要:
        //     Gets the object of an iconic output parameter
        public HObject GetOutputIconicParamObject(int index)
        {
            HCkE(EngineAPI.GetOutputIconicParamObject(call, index, out var key));
            GC.KeepAlive(this);
            return new HObject(key);
        }

        //
        // 摘要:
        //     Gets the object of an iconic output parameter
        public HObject GetOutputIconicParamObject(string name)
        {
            HCkE(EngineAPI.GetOutputIconicParamObject(call, name, out var key));
            GC.KeepAlive(this);
            return new HObject(key);
        }

        //
        // 摘要:
        //     Gets the value of an output control parameter
        public HObjectVector GetOutputIconicParamVector(int index)
        {
            HCkE(EngineAPI.GetOutputIconicParamVector(call, index, out var vector));
            GC.KeepAlive(this);
            return EngineAPI.GetAndDestroyObjectVector(vector);
        }

        //
        // 摘要:
        //     Gets the value of an output control parameter
        public HObjectVector GetOutputIconicParamVector(string name)
        {
            HCkE(EngineAPI.GetOutputIconicParamVector(call, name, out var vector));
            GC.KeepAlive(this);
            return EngineAPI.GetAndDestroyObjectVector(vector);
        }

        //
        // 摘要:
        //     Gets the image of an iconic output parameter
        public HImage GetOutputIconicParamImage(int index)
        {
            HCkE(EngineAPI.GetOutputIconicParamObject(call, index, out var key));
            GC.KeepAlive(this);
            EngineAPI.AssertObjectClass(key, "image", "main");
            return new HImage(key);
        }

        //
        // 摘要:
        //     Gets the image of an iconic output parameter
        public HImage GetOutputIconicParamImage(string name)
        {
            HCkE(EngineAPI.GetOutputIconicParamObject(call, name, out var key));
            GC.KeepAlive(this);
            EngineAPI.AssertObjectClass(key, "image", "main");
            return new HImage(key);
        }

        //
        // 摘要:
        //     Gets the region of an iconic output parameter
        public HRegion GetOutputIconicParamRegion(int index)
        {
            HCkE(EngineAPI.GetOutputIconicParamObject(call, index, out var key));
            GC.KeepAlive(this);
            EngineAPI.AssertObjectClass(key, "region", "main");
            return new HRegion(key);
        }

        //
        // 摘要:
        //     Gets the region of an iconic output parameter
        public HRegion GetOutputIconicParamRegion(string name)
        {
            HCkE(EngineAPI.GetOutputIconicParamObject(call, name, out var key));
            GC.KeepAlive(this);
            EngineAPI.AssertObjectClass(key, "region", "main");
            return new HRegion(key);
        }

        //
        // 摘要:
        //     Gets the xld contour of an iconic output parameter
        public HXLD GetOutputIconicParamXld(int index)
        {
            HCkE(EngineAPI.GetOutputIconicParamObject(call, index, out var key));
            GC.KeepAlive(this);
            EngineAPI.AssertObjectClass(key, "xld", "main");
            return new HXLD(key);
        }

        //
        // 摘要:
        //     Gets the xld contour of an iconic output parameter
        public HXLD GetOutputIconicParamXld(string name)
        {
            HCkE(EngineAPI.GetOutputIconicParamObject(call, name, out var key));
            GC.KeepAlive(this);
            EngineAPI.AssertObjectClass(key, "xld", "main");
            return new HXLD(key);
        }

        internal static void HCkE(int err)
        {
            EngineAPI.HCkE(err);
        }

        ~HDevProcedureCall()
        {
            try
            {
                Dispose();
            }
            catch (Exception)
            {
            }
        }

        void IDisposable.Dispose()
        {
            Dispose();
        }

        //
        // 摘要:
        //     Releases the resources used by this procedure call
        public virtual void Dispose()
        {
            if (call != IntPtr.Zero)
            {
                EngineAPI.DestroyProcedureCall(call);
                call = IntPtr.Zero;
            }

            GC.SuppressFinalize(this);
            GC.KeepAlive(this);
        }
    }
    //
    // 摘要:
    //     Encapsulates a loaded HDevelop program
    public class HDevProgram : IDisposable
    {
        private IntPtr program = IntPtr.Zero;

        private string name = "";

        private bool loaded;

        private HTuple varNamesIconic = new HTuple();

        private HTuple varNamesCtrl = new HTuple();

        private HTuple varDimsIconic = new HTuple();

        private HTuple varDimsCtrl = new HTuple();

        internal IntPtr Handle => program;

        //
        // 摘要:
        //     The name of the program
        public string Name => name;

        //
        // 摘要:
        //     Creates an empty program instance
        public HDevProgram()
        {
            HCkE(EngineAPI.CreateProgram(out program));
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Loads an HDevelop program
        public HDevProgram(string fileName)
            : this()
        {
            LoadProgram(fileName);
        }

        //
        // 摘要:
        //     Loads an HDevelop script
        //
        // 参数:
        //   fileName:
        //     Path and file name of the HDevelop script
        //
        // 言论:
        //     You can use this to exceute the program or local procedures.
        public void LoadProgram(string fileName)
        {
            HCkE(EngineAPI.LoadProgram(program, fileName));
            EngineAPI.GetProgramInfo(program, out name, out loaded, out varNamesIconic, out varNamesCtrl, out varDimsIconic, out varDimsCtrl);
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Creates a program call for this program
        public HDevProgramCall CreateCall()
        {
            return new HDevProgramCall(this);
        }

        //
        // 摘要:
        //     Create and execute a program call for this program
        public HDevProgramCall Execute()
        {
            HDevProgramCall hDevProgramCall = new HDevProgramCall(this);
            hDevProgramCall.Execute();
            return hDevProgramCall;
        }

        //
        // 摘要:
        //     Check the load state of the program
        public bool IsLoaded()
        {
            return loaded;
        }

        //
        // 摘要:
        //     Returns true if this class has not yet been disposed
        public bool IsInitialized()
        {
            return program != IntPtr.Zero;
        }

        //
        // 摘要:
        //     Gets the variable names used for iconic objects
        public HTuple GetIconicVarNames()
        {
            return varNamesIconic.Clone();
        }

        //
        // 摘要:
        //     Gets the variable names used for control values
        public HTuple GetCtrlVarNames()
        {
            return varNamesCtrl.Clone();
        }

        //
        // 摘要:
        //     Gets the variable dimensions used for iconic objects
        public HTuple GetIconicVarDimensions()
        {
            return varDimsIconic.Clone();
        }

        //
        // 摘要:
        //     Gets the variable dimensions used for control values
        public HTuple GetCtrlVarDimensions()
        {
            return varDimsCtrl.Clone();
        }

        //
        // 摘要:
        //     Gets the number of variables used for iconic objects. Note that variables are
        //     numbered from 1 to count.
        public int GetIconicVarCount()
        {
            return varNamesIconic.Length;
        }

        //
        // 摘要:
        //     Gets the number of variables used for control values. Note that variables are
        //     numbered from 1 to count.
        public int GetCtrlVarCount()
        {
            return varNamesCtrl.Length;
        }

        //
        // 摘要:
        //     Gets the name of a specific iconic variable
        public string GetIconicVarName(int index)
        {
            if (index < 1 || index > varNamesIconic.Length)
            {
                HDevEngineException.ThrowGeneric("Bad index for GetIconicVarName");
            }

            return varNamesIconic.SArr[index - 1];
        }

        //
        // 摘要:
        //     Gets the name of a specific control variable
        public string GetCtrlVarName(int index)
        {
            if (index < 1 || index > varNamesCtrl.Length)
            {
                HDevEngineException.ThrowGeneric("Bad index for GetCtrlVarName");
            }

            return varNamesCtrl.SArr[index - 1];
        }

        //
        // 摘要:
        //     Gets the dimension of a specific iconic variable
        public int GetIconicVarDimension(int index)
        {
            if (index < 1 || index > varDimsIconic.Length)
            {
                HDevEngineException.ThrowGeneric("Bad index for GetIconicVarDimension");
            }

            return varDimsIconic[index - 1];
        }

        //
        // 摘要:
        //     Gets the dimension of a specific control variable
        public int GetCtrlVarDimension(int index)
        {
            if (index < 1 || index > varDimsCtrl.Length)
            {
                HDevEngineException.ThrowGeneric("Bad index for GetCtrlVarDimension");
            }

            return varDimsCtrl[index - 1];
        }

        //
        // 摘要:
        //     Returns the names of used local and external procedures
        public HTuple GetUsedProcedureNames()
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(EngineAPI.GetUsedProcedureNamesForProgram(program, tuple));
            GC.KeepAlive(this);
            HTuple result = HalconAPI.LoadTuple(tuple);
            HCkE(HalconAPI.DestroyTuple(tuple));
            return result;
        }

        //
        // 摘要:
        //     Compile all procedures that are used by the program and that can be compiled
        //     with a just-in-time compiler. The method returns true when all used procedures
        //     could be compiled by the just-in-time compiler. Procedures that could not be
        //     compiled are called normally by the HDevEngine interpreter. To check which procedure
        //     could not be compiled and what the reason is for that start HDevelop and check
        //     there the compilation states.
        public bool CompileUsedProcedures()
        {
            HCkE(EngineAPI.CompileUsedProceduresForProgram(program, out var ret));
            GC.KeepAlive(this);
            return ret;
        }

        //
        // 摘要:
        //     Returns the names of all local procedures
        public HTuple GetLocalProcedureNames()
        {
            HCkE(HalconAPI.CreateTuple(out var tuple));
            HCkE(EngineAPI.GetLocalProcedureNames(program, tuple));
            GC.KeepAlive(this);
            HTuple result = HalconAPI.LoadTuple(tuple);
            HCkE(HalconAPI.DestroyTuple(tuple));
            return result;
        }

        internal static void HCkE(int err)
        {
            EngineAPI.HCkE(err);
        }

        ~HDevProgram()
        {
            try
            {
                Dispose();
            }
            catch (Exception)
            {
            }
        }

        void IDisposable.Dispose()
        {
            Dispose();
        }

        //
        // 摘要:
        //     Releases the resources used by this engine
        public virtual void Dispose()
        {
            if (program != IntPtr.Zero)
            {
                EngineAPI.DestroyProgram(program);
                program = IntPtr.Zero;
                loaded = false;
            }

            GC.SuppressFinalize(this);
            GC.KeepAlive(this);
        }
    }
    //
    // 摘要:
    //     Manages an execution instance for an HDevelop program
    public class HDevProgramCall : IDisposable
    {
        private IntPtr call = IntPtr.Zero;

        private HDevProgram program;

        //
        // 摘要:
        //     Creates a program call for the specified program
        public HDevProgramCall(HDevProgram program)
        {
            HCkE(EngineAPI.CreateProgramCall(program.Handle, out call));
            GC.KeepAlive(this);
            this.program = program;
        }

        //
        // 摘要:
        //     Returns true if this class has not yet been disposed
        public bool IsInitialized()
        {
            return call != IntPtr.Zero;
        }

        //
        // 摘要:
        //     Gets the program associated with this program call
        public HDevProgram GetProgram()
        {
            return program;
        }

        //
        // 摘要:
        //     Executes the program
        public void Execute()
        {
            HCkE(EngineAPI.ExecuteProgramCall(call));
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Stops execution on first line of program.
        //
        // 言论:
        //     This is intended for debugging purposes when you wish to step through a specific
        //     program call. It only has an effect when a debug server is running and it will
        //     only stop once.
        public void SetWaitForDebugConnection(bool wait_once)
        {
            HCkE(EngineAPI.SetWaitForDebugConnectionProgramCall(call, wait_once));
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Resets the program execution
        public void Reset()
        {
            HCkE(EngineAPI.ResetProgramCall(call));
            GC.KeepAlive(this);
        }

        //
        // 摘要:
        //     Gets the value of a control variable (in main)
        public HTuple GetCtrlVarTuple(int index)
        {
            HCkE(EngineAPI.GetCtrlVarTuple(call, index, out var tuple));
            GC.KeepAlive(this);
            return HalconAPI.LoadTuple(tuple);
        }

        //
        // 摘要:
        //     Gets the values of a control vector variable (in main)
        public HTupleVector GetCtrlVarVector(int index)
        {
            HCkE(EngineAPI.GetCtrlVarVector(call, index, out var vector));
            GC.KeepAlive(this);
            return EngineAPI.GetAndDestroyTupleVector(vector);
        }

        //
        // 摘要:
        //     Gets the value of a control variable (in main)
        public HTuple GetCtrlVarTuple(string name)
        {
            HCkE(EngineAPI.GetCtrlVarTuple(call, name, out var tuple));
            GC.KeepAlive(this);
            return HalconAPI.LoadTuple(tuple);
        }

        //
        // 摘要:
        //     Gets the values of a control vector variable (in main)
        public HTupleVector GetCtrlVarVector(string name)
        {
            HCkE(EngineAPI.GetCtrlVarVector(call, name, out var vector));
            GC.KeepAlive(this);
            return EngineAPI.GetAndDestroyTupleVector(vector);
        }

        //
        // 摘要:
        //     Gets the object of an iconic variable (in main)
        public HObject GetIconicVarObject(int index)
        {
            HCkE(EngineAPI.GetIconicVarObject(call, index, out var key));
            GC.KeepAlive(this);
            return new HObject(key);
        }

        //
        // 摘要:
        //     Gets the values of an iconic vector variable (in main)
        public HObjectVector GetIconicVarVector(int index)
        {
            HCkE(EngineAPI.GetIconicVarVector(call, index, out var vector));
            GC.KeepAlive(this);
            return EngineAPI.GetAndDestroyObjectVector(vector);
        }

        //
        // 摘要:
        //     Gets the object of an iconic variable (in main)
        public HObject GetIconicVarObject(string name)
        {
            HCkE(EngineAPI.GetIconicVarObject(call, name, out var key));
            GC.KeepAlive(this);
            return new HObject(key);
        }

        //
        // 摘要:
        //     Gets the values of an iconic vector variable (in main)
        public HObjectVector GetIconicVarVector(string name)
        {
            HCkE(EngineAPI.GetIconicVarVector(call, name, out var vector));
            GC.KeepAlive(this);
            return EngineAPI.GetAndDestroyObjectVector(vector);
        }

        //
        // 摘要:
        //     Gets the image of an iconic variable (in main)
        public HImage GetIconicVarImage(int index)
        {
            HCkE(EngineAPI.GetIconicVarObject(call, index, out var key));
            GC.KeepAlive(this);
            EngineAPI.AssertObjectClass(key, "image", "main");
            return new HImage(key);
        }

        //
        // 摘要:
        //     Gets the image of an iconic variable (in main)
        public HImage GetIconicVarImage(string name)
        {
            HCkE(EngineAPI.GetIconicVarObject(call, name, out var key));
            GC.KeepAlive(this);
            EngineAPI.AssertObjectClass(key, "image", "main");
            return new HImage(key);
        }

        //
        // 摘要:
        //     Gets the region of an iconic variable (in main)
        public HRegion GetIconicVarRegion(int index)
        {
            HCkE(EngineAPI.GetIconicVarObject(call, index, out var key));
            GC.KeepAlive(this);
            EngineAPI.AssertObjectClass(key, "region", "main");
            return new HRegion(key);
        }

        //
        // 摘要:
        //     Gets the region of an iconic variable (in main)
        public HRegion GetIconicVarRegion(string name)
        {
            HCkE(EngineAPI.GetIconicVarObject(call, name, out var key));
            GC.KeepAlive(this);
            EngineAPI.AssertObjectClass(key, "region", "main");
            return new HRegion(key);
        }

        //
        // 摘要:
        //     Gets the xld contour of an iconic variable (in main)
        public HXLD GetIconicVarXld(int index)
        {
            HCkE(EngineAPI.GetIconicVarObject(call, index, out var key));
            GC.KeepAlive(this);
            EngineAPI.AssertObjectClass(key, "xld", "main");
            return new HXLD(key);
        }

        //
        // 摘要:
        //     Gets the xld contour of an iconic variable (in main)
        public HXLD GetIconicVarXld(string name)
        {
            HCkE(EngineAPI.GetIconicVarObject(call, name, out var key));
            GC.KeepAlive(this);
            EngineAPI.AssertObjectClass(key, "xld", "main");
            return new HXLD(key);
        }

        internal static void HCkE(int err)
        {
            EngineAPI.HCkE(err);
        }

        ~HDevProgramCall()
        {
            try
            {
                Dispose();
            }
            catch (Exception)
            {
            }
        }

        void IDisposable.Dispose()
        {
            Dispose();
        }

        //
        // 摘要:
        //     Releases the resources used by this engine
        public virtual void Dispose()
        {
            if (call != IntPtr.Zero)
            {
                EngineAPI.DestroyProgramCall(call);
                call = IntPtr.Zero;
            }

            program = null;
            GC.SuppressFinalize(this);
            GC.KeepAlive(this);
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

多巴胺耐受

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值