コード例 #1
0
 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;
 }
コード例 #2
0
 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;
 }
コード例 #3
0
 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;
 }
コード例 #4
0
        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;
        }