public bool LookupItemIDs(string itemID, int[] propertyIDs, out OPCPropertyItem[] propertyItems) { propertyItems = null; int count = propertyIDs.Length; if (count < 1) { return(false); } IntPtr ptrErr; IntPtr ptrIds; int hresult = ifItmProps.LookupItemIDs(itemID, count, propertyIDs, out ptrIds, out ptrErr); if (HRESULTS.Failed(hresult)) { Marshal.ThrowExceptionForHR(hresult); } int runIds = (int)ptrIds; int runErr = (int)ptrErr; if ((runIds == 0) || (runErr == 0)) { Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT); } propertyItems = new OPCPropertyItem[count]; IntPtr ptrString; for (int i = 0; i < count; i++) { propertyItems[i] = new OPCPropertyItem(); propertyItems[i].PropertyID = propertyIDs[i]; propertyItems[i].Error = Marshal.ReadInt32((IntPtr)runErr); runErr += 4; if (propertyItems[i].Error == HRESULTS.S_OK) { ptrString = (IntPtr)Marshal.ReadInt32((IntPtr)runIds); propertyItems[i].newItemID = Marshal.PtrToStringUni(ptrString); Marshal.FreeCoTaskMem(ptrString); } else { propertyItems[i].newItemID = null; } runIds += 4; } Marshal.FreeCoTaskMem(ptrIds); Marshal.FreeCoTaskMem(ptrErr); return(hresult == HRESULTS.S_OK); }
public bool LookupItemIDs( string itemID, int[] propertyIDs, out OPCPropertyItem[] propertyItems ) { propertyItems = null; int count = propertyIDs.Length; if( count < 1 ) return false; IntPtr ptrErr; IntPtr ptrIds; int hresult = ifItmProps.LookupItemIDs( itemID, count, propertyIDs, out ptrIds, out ptrErr ); if( HRESULTS.Failed( hresult ) ) Marshal.ThrowExceptionForHR( hresult ); int runIds = (int) ptrIds; int runErr = (int) ptrErr; if( (runIds == 0) || (runErr == 0) ) Marshal.ThrowExceptionForHR( HRESULTS.E_ABORT ); propertyItems = new OPCPropertyItem[ count ]; IntPtr ptrString; for( int i = 0; i < count; i++ ) { propertyItems[i] = new OPCPropertyItem(); propertyItems[i].PropertyID = propertyIDs[i]; propertyItems[i].Error = Marshal.ReadInt32( (IntPtr) runErr ); runErr += 4; if( propertyItems[i].Error == HRESULTS.S_OK ) { ptrString = (IntPtr) Marshal.ReadInt32( (IntPtr) runIds ); propertyItems[i].newItemID = Marshal.PtrToStringUni( ptrString ); Marshal.FreeCoTaskMem( ptrString ); } else propertyItems[i].newItemID = null; runIds += 4; } Marshal.FreeCoTaskMem( ptrIds ); Marshal.FreeCoTaskMem( ptrErr ); return hresult == HRESULTS.S_OK; }