/// <summary> /// Allocates and marshals an arary of OPCITEMPROPERTY structures. /// </summary> internal static OpcRcw.Da.OPCITEMPROPERTY GetItemProperty(TsCDaItemProperty input) { OpcRcw.Da.OPCITEMPROPERTY output = new OpcRcw.Da.OPCITEMPROPERTY(); if (input != null) { output.dwPropertyID = input.ID.Code; output.szDescription = input.Description; output.vtDataType = (short)Technosoftware.DaAeHdaClient.Com.Interop.GetType(input.DataType); output.vValue = MarshalPropertyValue(input.ID, input.Value); output.wReserved = 0; output.hrErrorID = Technosoftware.DaAeHdaClient.Com.Interop.GetResultID(input.Result); // set the property data type. TsDaPropertyDescription description = TsDaPropertyDescription.Find(input.ID); if (description != null) { output.vtDataType = (short)Technosoftware.DaAeHdaClient.Com.Interop.GetType(description.Type); } // convert unified DA code to COM DA code. if (input.Result == OpcResult.Da.E_WRITEONLY) { output.hrErrorID = Result.E_BADRIGHTS; } } return(output); }
/// <summary> /// Unmarshals and deallocates a OPCITEMPROPERTY structures. /// </summary> internal static ItemProperty GetItemProperty(IntPtr pInput, bool deallocate) { ItemProperty output = null; if (pInput != IntPtr.Zero) { OpcRcw.Da.OPCITEMPROPERTY property = (OpcRcw.Da.OPCITEMPROPERTY)Marshal.PtrToStructure(pInput, typeof(OpcRcw.Da.OPCITEMPROPERTY)); output = new ItemProperty(); output.ID = GetPropertyID(property.dwPropertyID); output.Description = property.szDescription; output.DataType = OpcCom.Interop.GetType((VarEnum)property.vtDataType); output.ItemPath = null; output.ItemName = property.szItemID; output.Value = UnmarshalPropertyValue(output.ID, property.vValue); output.ResultID = OpcCom.Interop.GetResultID(property.hrErrorID); // convert COM DA code to unified DA code. if (property.hrErrorID == ResultIDs.E_BADRIGHTS) { output.ResultID = new ResultID(ResultID.Da.E_WRITEONLY, ResultIDs.E_BADRIGHTS); } if (deallocate) { Marshal.DestroyStructure(pInput, typeof(OpcRcw.Da.OPCITEMPROPERTY)); } } return(output); }
/// <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); }