Esempio n. 1
0
        // ------------------------ IOPCItemProperties ---------------

        public void QueryAvailableProperties(string itemID, out OPCProperty[] opcProperties)
        {
            opcProperties = null;

            int    count = 0;
            IntPtr ptrID;
            IntPtr ptrDesc;
            IntPtr ptrTyp;

            ifItmProps.QueryAvailableProperties(itemID, out count, out ptrID, out ptrDesc, out ptrTyp);
            if ((count == 0) || (count > 10000))
            {
                return;
            }

            int runID   = (int)ptrID;
            int runDesc = (int)ptrDesc;
            int runTyp  = (int)ptrTyp;

            if ((runID == 0) || (runDesc == 0) || (runTyp == 0))
            {
                Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);
            }

            opcProperties = new OPCProperty[count];

            IntPtr ptrString;

            for (int i = 0; i < count; i++)
            {
                opcProperties[i] = new OPCProperty();

                opcProperties[i].PropertyID = Marshal.ReadInt32((IntPtr)runID);
                runID += 4;

                ptrString = (IntPtr)Marshal.ReadInt32((IntPtr)runDesc);
                runDesc  += 4;
                opcProperties[i].Description = Marshal.PtrToStringUni(ptrString);
                Marshal.FreeCoTaskMem(ptrString);

                opcProperties[i].DataType = (VarEnum)Marshal.ReadInt16((IntPtr)runTyp);
                runTyp += 2;
            }

            Marshal.FreeCoTaskMem(ptrID);
            Marshal.FreeCoTaskMem(ptrDesc);
            Marshal.FreeCoTaskMem(ptrTyp);
        }
        // ------------------------ IOPCItemProperties ---------------
        public void QueryAvailableProperties( string itemID, out OPCProperty[] opcProperties )
        {
            opcProperties = null;

            int	count = 0;
            IntPtr	ptrID;
            IntPtr	ptrDesc;
            IntPtr	ptrTyp;
            ifItmProps.QueryAvailableProperties( itemID, out count, out ptrID, out ptrDesc, out ptrTyp );
            if( (count == 0) || (count > 10000) )
            return;

            int	runID	= (int) ptrID;
            int	runDesc	= (int) ptrDesc;
            int	runTyp	= (int) ptrTyp;
            if( (runID == 0) || (runDesc == 0) || (runTyp == 0) )
            Marshal.ThrowExceptionForHR( HRESULTS.E_ABORT );

            opcProperties = new OPCProperty[ count ];

            IntPtr ptrString;
            for( int i = 0; i < count; i++ )
            {
            opcProperties[i] = new OPCProperty();

            opcProperties[i].PropertyID = Marshal.ReadInt32( (IntPtr) runID );
            runID += 4;

            ptrString = (IntPtr) Marshal.ReadInt32( (IntPtr) runDesc );
            runDesc += 4;
            opcProperties[i].Description = Marshal.PtrToStringUni( ptrString );
            Marshal.FreeCoTaskMem( ptrString );

            opcProperties[i].DataType = (VarEnum) Marshal.ReadInt16( (IntPtr) runTyp );
            runTyp += 2;
            }

            Marshal.FreeCoTaskMem( ptrID );
            Marshal.FreeCoTaskMem( ptrDesc );
            Marshal.FreeCoTaskMem( ptrTyp );
        }