public OPCITEMRESULT[] AddItems( OPCITEMDEF[] itemDefinitions, out HRESULT[] errors) { var _errors = new HRESULT[itemDefinitions.Length]; OPCITEMRESULT[] result = DoComCall(ComObject, "IOPCItemMgt::AddItems", () => { IntPtr ppAddResults; ComObject.AddItems(itemDefinitions.Length, itemDefinitions, out ppAddResults, out _errors); OPCITEMRESULT[] opcDaItemResults = ArrayHelpers.CreateOpcItemResults(itemDefinitions, ppAddResults); Marshal.FreeCoTaskMem(ppAddResults); return opcDaItemResults; }, itemDefinitions.Length, itemDefinitions); errors = _errors; return result; }
internal OPCITEMDEF ToStruct() { var itemDef = new OPCITEMDEF(); itemDef.szItemID = ItemId; itemDef.bActive = IsActive ? 1 : 0; itemDef.hClient = 0; itemDef.szAccessPath = AccessPath; itemDef.vtRequestedDataType = (short) TypeConverter.ToVarEnum(RequestedDataType); if (Blob != null) { itemDef.dwBlobSize = Blob.Length; itemDef.pBlob = Marshal.AllocCoTaskMem(Blob.Length*Marshal.SizeOf(typeof (byte))); Marshal.Copy(Blob, 0, itemDef.pBlob, Blob.Length); } else { itemDef.dwBlobSize = 0; itemDef.pBlob = IntPtr.Zero; } return itemDef; }
public static OPCITEMDEF[] CreateOPITEMDEFs(IList<OpcDaItemDefinition> opcItemDefinitions) { var pItemArray = new OPCITEMDEF[opcItemDefinitions.Count]; for (int i = 0; i < opcItemDefinitions.Count; i++) { pItemArray[i] = opcItemDefinitions[i].ToStruct(); } return pItemArray; }
public static OPCITEMRESULT[] CreateOpcItemResults(OPCITEMDEF[] pItemArray, IntPtr ppAddResults) { var results = new OPCITEMRESULT[pItemArray.Length]; for (int i = 0; i < pItemArray.Length; i++) { IntPtr current = ppAddResults + i*Marshal.SizeOf(typeof (OPCITEMRESULT)); results[i] = (OPCITEMRESULT) Marshal.PtrToStructure(current, typeof (OPCITEMRESULT)); Marshal.DestroyStructure(current, typeof (OPCITEMRESULT)); Marshal.FreeCoTaskMem(pItemArray[i].pBlob); // Delete allocated blobs } return results; }