Beispiel #1
0
        public bool GetItemProperties(string itemID, int[] propertyIDs, out OPCPropertyData[] propertiesData)
        {
            propertiesData = null;
            int count = propertyIDs.Length;

            if (count < 1)
            {
                return(false);
            }

            IntPtr ptrDat;
            IntPtr ptrErr;
            int    hresult = ifItmProps.GetItemProperties(itemID, count, propertyIDs, out ptrDat, out ptrErr);

            if (HRESULTS.Failed(hresult))
            {
                Marshal.ThrowExceptionForHR(hresult);
            }

            int runDat = (int)ptrDat;
            int runErr = (int)ptrErr;

            if ((runDat == 0) || (runErr == 0))
            {
                Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);
            }

            propertiesData = new OPCPropertyData[count];

            for (int i = 0; i < count; i++)
            {
                propertiesData[i]            = new OPCPropertyData();
                propertiesData[i].PropertyID = propertyIDs[i];

                propertiesData[i].Error = Marshal.ReadInt32((IntPtr)runErr);
                runErr += 4;

                if (propertiesData[i].Error == HRESULTS.S_OK)
                {
                    propertiesData[i].Data = Marshal.GetObjectForNativeVariant((IntPtr)runDat);
                    DUMMY_VARIANT.VariantClear((IntPtr)runDat);
                }
                else
                {
                    propertiesData[i].Data = null;
                }

                runDat += DUMMY_VARIANT.ConstSize;
            }

            Marshal.FreeCoTaskMem(ptrDat);
            Marshal.FreeCoTaskMem(ptrErr);
            return(hresult == HRESULTS.S_OK);
        }
        public bool GetItemProperties( string itemID, int[] propertyIDs, out OPCPropertyData[] propertiesData )
        {
            propertiesData = null;
            int	count = propertyIDs.Length;
            if( count < 1 )
            return false;

            IntPtr	ptrDat;
            IntPtr	ptrErr;
            int	hresult = ifItmProps.GetItemProperties( itemID, count, propertyIDs, out ptrDat, out ptrErr );
            if( HRESULTS.Failed( hresult ) )
            Marshal.ThrowExceptionForHR( hresult );

            int	runDat = (int) ptrDat;
            int	runErr = (int) ptrErr;
            if( (runDat == 0) || (runErr == 0) )
            Marshal.ThrowExceptionForHR( HRESULTS.E_ABORT );

            propertiesData = new OPCPropertyData[ count ];

            for( int i = 0; i < count; i++ )
            {
            propertiesData[i] = new OPCPropertyData();
            propertiesData[i].PropertyID = propertyIDs[i];

            propertiesData[i].Error = Marshal.ReadInt32( (IntPtr) runErr );
            runErr += 4;

            if( propertiesData[i].Error == HRESULTS.S_OK )
                {
                propertiesData[i].Data = Marshal.GetObjectForNativeVariant( (IntPtr) runDat );
                DUMMY_VARIANT.VariantClear( (IntPtr) runDat );
                }
            else
                propertiesData[i].Data = null;

            runDat += DUMMY_VARIANT.ConstSize;
            }

            Marshal.FreeCoTaskMem( ptrDat );
            Marshal.FreeCoTaskMem( ptrErr );
            return hresult == HRESULTS.S_OK;
        }