Пример #1
0
        /// <summary>
        /// Allocates and marshals an array of OPCITEMPROPERTIES structures.
        /// </summary>
        internal static IntPtr GetItemPropertyCollections(TsCDaItemPropertyCollection[] input)
        {
            IntPtr output = IntPtr.Zero;

            if (input != null && input.Length > 0)
            {
                output = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(OpcRcw.Da.OPCITEMPROPERTIES)) * input.Length);

                IntPtr pos = output;

                for (int ii = 0; ii < input.Length; ii++)
                {
                    OpcRcw.Da.OPCITEMPROPERTIES properties = new OpcRcw.Da.OPCITEMPROPERTIES();

                    if (input[ii].Count > 0)
                    {
                        properties = GetItemProperties((TsCDaItemProperty[])input[ii].ToArray(typeof(TsCDaItemProperty)));
                    }

                    properties.hrErrorID = Technosoftware.DaAeHdaClient.Com.Interop.GetResultID(input[ii].Result);

                    Marshal.StructureToPtr(properties, pos, false);

                    pos = (IntPtr)(pos.ToInt64() + Marshal.SizeOf(typeof(OpcRcw.Da.OPCITEMPROPERTIES)));
                }
            }

            return(output);
        }
Пример #2
0
        /// <summary>
        /// Unmarshals and deallocates a OPCITEMPROPERTIES structures.
        /// </summary>
        internal static TsCDaItemProperty[] GetItemProperties(ref OpcRcw.Da.OPCITEMPROPERTIES input, bool deallocate)
        {
            TsCDaItemProperty[] output = null;

            if (input.dwNumProperties > 0)
            {
                output = new TsCDaItemProperty[input.dwNumProperties];

                IntPtr pos = input.pItemProperties;

                for (int ii = 0; ii < output.Length; ii++)
                {
                    try
                    {
                        output[ii] = GetItemProperty(pos, deallocate);
                    }
                    catch (Exception e)
                    {
                        output[ii]             = new TsCDaItemProperty();
                        output[ii].Description = e.Message;
                        output[ii].Result      = OpcResult.E_FAIL;
                    }

                    pos = (IntPtr)(pos.ToInt64() + Marshal.SizeOf(typeof(OpcRcw.Da.OPCITEMPROPERTY)));
                }

                if (deallocate)
                {
                    Marshal.FreeCoTaskMem(input.pItemProperties);
                    input.pItemProperties = IntPtr.Zero;
                }
            }

            return(output);
        }
Пример #3
0
        /// <summary>
        /// Unmarshals and deallocates an array of OPCITEMPROPERTIES structures.
        /// </summary>
        internal static TsCDaItemPropertyCollection[] GetItemPropertyCollections(ref IntPtr pInput, int count, bool deallocate)
        {
            TsCDaItemPropertyCollection[] output = null;

            if (pInput != IntPtr.Zero && count > 0)
            {
                output = new TsCDaItemPropertyCollection[count];

                IntPtr pos = pInput;

                for (int ii = 0; ii < count; ii++)
                {
                    OpcRcw.Da.OPCITEMPROPERTIES list = (OpcRcw.Da.OPCITEMPROPERTIES)Marshal.PtrToStructure(pos, typeof(OpcRcw.Da.OPCITEMPROPERTIES));

                    output[ii]          = new TsCDaItemPropertyCollection();
                    output[ii].ItemPath = null;
                    output[ii].ItemName = null;
                    output[ii].Result   = Technosoftware.DaAeHdaClient.Com.Interop.GetResultID(list.hrErrorID);

                    TsCDaItemProperty[] properties = GetItemProperties(ref list, deallocate);

                    if (properties != null)
                    {
                        output[ii].AddRange(properties);
                    }

                    if (deallocate)
                    {
                        Marshal.DestroyStructure(pos, typeof(OpcRcw.Da.OPCITEMPROPERTIES));
                    }

                    pos = (IntPtr)(pos.ToInt64() + Marshal.SizeOf(typeof(OpcRcw.Da.OPCITEMPROPERTIES)));
                }

                if (deallocate)
                {
                    Marshal.FreeCoTaskMem(pInput);
                    pInput = IntPtr.Zero;
                }
            }

            return(output);
        }
Пример #4
0
        /// <summary>
        /// Allocates and marshals an array of OPCITEMPROPERTIES structures.
        /// </summary>
        internal static OpcRcw.Da.OPCITEMPROPERTIES GetItemProperties(TsCDaItemProperty[] input)
        {
            OpcRcw.Da.OPCITEMPROPERTIES output = new OpcRcw.Da.OPCITEMPROPERTIES();

            if (input != null && input.Length > 0)
            {
                output.hrErrorID       = Result.S_OK;
                output.dwReserved      = 0;
                output.dwNumProperties = input.Length;
                output.pItemProperties = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(OpcRcw.Da.OPCITEMPROPERTY)) * input.Length);

                bool error = false;

                IntPtr pos = output.pItemProperties;

                for (int ii = 0; ii < input.Length; ii++)
                {
                    OpcRcw.Da.OPCITEMPROPERTY property = GetItemProperty(input[ii]);
                    Marshal.StructureToPtr(property, pos, false);
                    pos = (IntPtr)(pos.ToInt64() + Marshal.SizeOf(typeof(OpcRcw.Da.OPCITEMPROPERTY)));

                    if (input[ii].Result.Failed())
                    {
                        error = true;
                    }
                }

                // set flag indicating one or more properties contained errors.
                if (error)
                {
                    output.hrErrorID = Result.S_FALSE;
                }
            }

            return(output);
        }