コード例 #1
0
        public OpcServerCategory[] GetCategories(Guid clsid)
        {
            IEnumGUID catEnumerator = null;

            try
            {
                catEnumerator = _catInformation.EnumImplCategoriesOfClass(clsid);

                var catids = new Guid[MaxItemsPerRequest];
                int fetched;
                var result = new List <OpcServerCategory>();
                do
                {
                    catEnumerator.Next(catids.Length, catids, out fetched);
                    for (var i = 0; i < fetched; i++)
                    {
                        var catid             = catids[i];
                        var opcServerCategory = OpcServerCategory.Get(catid);
                        if (opcServerCategory != null)
                        {
                            result.Add(opcServerCategory);
                        }
                    }
                } while (fetched != 0);

                return(result.ToArray());
            }
            finally
            {
                if (catEnumerator != null)
                {
                    Marshal.ReleaseComObject(catEnumerator);
                }
            }
        }
コード例 #2
0
        private SERVERPARAM[] GetServerParam(IOPCServerList svrList, Guid catid)
        {
            // get list of servers in the specified specification.
            IEnumGUID enumeratorObject = null; //enumeratorObject has been changed from object to IEnumGUID

            svrList.EnumClassesOfCategories(
                1,
                new Guid[] { catid },
                0,
                null,
                out enumeratorObject);

            ArrayList prms = new ArrayList();

            IEnumGUID enumerator = enumeratorObject;

            int fetched = 0;

            Guid[]      buffer = new Guid[100];
            SERVERPARAM prm;

            do
            {
                IntPtr _buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(Guid)) * 100);                //alloc
                try
                {
                    enumerator.Next(100, buffer, out fetched);

                    IntPtr pPos = _buffer;
                    for (int i = 0; i < fetched; i++)
                    {
                        prm.clsid = (Guid)Marshal.PtrToStructure(pPos, typeof(Guid));
                        pPos      = (IntPtr)(pPos.ToInt64() + Marshal.SizeOf(typeof(Guid)));
                        //prm.clsid = bufferPtr[i];
                        svrList.GetClassDetails(
                            ref prm.clsid,
                            out prm.progID,
                            out prm.description);
                        prms.Add(prm);
                    }
                }
                catch
                {
                    break;
                }
                finally
                {
                    Marshal.FreeCoTaskMem(_buffer);//alloc�� ���� Ǯ��д�.
                }
            }while (fetched > 0);

            return((SERVERPARAM[])prms.ToArray(typeof(SERVERPARAM)));
        }
コード例 #3
0
        /*------------------------------------------------------
        *  Get Server Parameter
        *
        *  ------------------------------------------------------*/
        private SERVERPARAM[] GetServerParam(IOPCServerList svrList, Guid catid, out int nServerCnt)
        {
            // Get Server List
            IEnumGUID enumeratorObject = null;

            svrList.EnumClassesOfCategories(1, new Guid[] { catid }, 0, null, out enumeratorObject);

            ArrayList prms = new ArrayList();

            IEnumGUID enumerator = enumeratorObject;

            int fetched = 0;

            Guid[]      buffer = new Guid[100];
            SERVERPARAM prm;

            nServerCnt = 0;
            do
            {
                IntPtr _buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(Guid)) * 100);
                try
                {
                    enumerator.Next(100, buffer, out fetched);
                    IntPtr pPos = _buffer;
                    for (int i = 0; i < fetched; i++)
                    {
                        prm.clsid       = (Guid)Marshal.PtrToStructure(pPos, typeof(Guid));
                        pPos            = (IntPtr)(pPos.ToInt64() + Marshal.SizeOf(typeof(Guid)));
                        prm.progID      = "";
                        prm.description = "";
                        svrList.GetClassDetails(ref prm.clsid, out prm.progID, out prm.description);
                        prms.Add(prm);
                        nServerCnt++;
                    }
                }
                catch
                {
                    break;
                }
                finally
                {
                    Marshal.FreeCoTaskMem(_buffer);
                }
            }while (fetched > 0);

            return((SERVERPARAM[])prms.ToArray(typeof(SERVERPARAM)));
        }
コード例 #4
0
        //=====================================================================
        // IEnumGUID

        /// <summary>
        /// fetches next group of GUIDs.
        /// </summary>
        public Guid[] Next(int count)
        {
            IntPtr buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(Guid)) * count);

            try
            {
                int fetched = 0;

                try
                {
                    m_enumerator.Next(
                        count,
                        buffer,
                        out fetched);
                }
                catch (Exception)
                {
                    return(null);
                }

                if (fetched == 0)
                {
                    return(null);
                }

                IntPtr pPos    = buffer;
                Guid[] results = new Guid[fetched];

                for (int ii = 0; ii < fetched; ii++)
                {
                    results[ii] = (Guid)Marshal.PtrToStructure(pPos, typeof(Guid));
                    pPos        = (IntPtr)(pPos.ToInt64() + Marshal.SizeOf(typeof(Guid)));
                }

                return(results);
            }
            finally
            {
                Marshal.FreeCoTaskMem(buffer);
            }
        }
コード例 #5
0
ファイル: DxpSimpleClass.cs プロジェクト: kumo203/YascPcDcs
        // Token: 0x0600000A RID: 10 RVA: 0x000024D4 File Offset: 0x000006D4
        private DxpSimpleClass.SERVERPARAM[] GetServerParam(IOPCServerList svrList, Guid catid, out int nServerCnt)
        {
            IEnumGUID enumGUID = null;

            svrList.EnumClassesOfCategories(1, new Guid[]
            {
                catid
            }, 0, null, out enumGUID);
            ArrayList arrayList = new ArrayList();
            int       num       = 0;

            Guid[] array = new Guid[100];
            nServerCnt = 0;
            do
            {
                try
                {
                    enumGUID.Next(array.Length, array, out num);
                    for (int i = 0; i < num; i++)
                    {
                        DxpSimpleClass.SERVERPARAM serverparam;
                        serverparam.clsid = array[i];
                        svrList.GetClassDetails(ref serverparam.clsid, out serverparam.progID, out serverparam.description);
                        arrayList.Add(serverparam);
                        nServerCnt++;
                    }
                }
                catch
                {
                    break;
                }
            }while (num > 0);
            Marshal.ReleaseComObject(enumGUID);
            enumGUID = null;
            return((DxpSimpleClass.SERVERPARAM[])arrayList.ToArray(typeof(DxpSimpleClass.SERVERPARAM)));
        }
コード例 #6
0
        /// <summary>
        /// Fetches the classes in the specified categories.
        /// </summary>
        public static List <Guid> EnumClassesInCategories(params Guid[] categories)
        {
            ICatInformation manager = (ICatInformation)CreateLocalServer(CLSID_StdComponentCategoriesMgr);

            object unknown = null;

            try
            {
                manager.EnumClassesOfCategories(
                    1,
                    categories,
                    0,
                    null,
                    out unknown);

                IEnumGUID enumerator = (IEnumGUID)unknown;

                List <Guid> classes = new List <Guid>();

                Guid[] buffer = new Guid[10];

                while (true)
                {
                    int fetched = 0;

                    IntPtr pGuids = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(Guid)) * buffer.Length);

                    try
                    {
                        enumerator.Next(buffer.Length, pGuids, out fetched);

                        if (fetched == 0)
                        {
                            break;
                        }

                        IntPtr pos = pGuids;

                        for (int ii = 0; ii < fetched; ii++)
                        {
                            buffer[ii] = (Guid)Marshal.PtrToStructure(pos, typeof(Guid));
                            pos        = (IntPtr)(pos.ToInt64() + Marshal.SizeOf(typeof(Guid)));
                        }
                    }
                    finally
                    {
                        Marshal.FreeCoTaskMem(pGuids);
                    }

                    for (int ii = 0; ii < fetched; ii++)
                    {
                        classes.Add(buffer[ii]);
                    }
                }

                return(classes);
            }
            finally
            {
                ReleaseServer(unknown);
                ReleaseServer(manager);
            }
        }
コード例 #7
0
        public void GetServerList(Guid[] catList, out string[] Servers, out Guid[] ClsIDs)
        {
            object obj2;

            Servers = null;
            ClsIDs  = null;
            if (this.ifSrvList == null)
            {
                throw new Exception(String.Format("GetServerList failed with error code {hr}", -2147467262));
            }
            this.ifSrvList.EnumClassesOfCategories(catList.Length, catList, 0, null, out obj2);
            if (obj2 != null)
            {
                IEnumGUID o = (IEnumGUID)obj2;
                obj2 = null;
                o.Reset();
                int    index     = 0;
                Guid   rgelt     = this.CLSID_OPCEnum;
                Guid[] guidArray = new Guid[50];

                int pceltFetched = 0;

                do
                {
                    o.Next(1, ref rgelt, out pceltFetched);
                    if (pceltFetched > 0)
                    {
                        guidArray[index] = rgelt;
                        index++;
                    }
                }while ((pceltFetched > 0) && (index < guidArray.Length));

                Marshal.ReleaseComObject(o);
                o = null;
                string[] strArray   = new string[index];
                Guid[]   guidArray2 = new Guid[index];
                int      num3       = 0;
                for (int i = 0; i < index; i++)
                {
                    string ppszProgID   = null;
                    string ppszUserType = null;
                    try
                    {
                        this.ifSrvList.GetClassDetails(ref guidArray[i], out ppszProgID, out ppszUserType);
                        strArray[num3]   = ppszProgID;
                        guidArray2[num3] = guidArray[i];
                        num3++;
                    }
                    catch
                    {
                    }
                }
                if (num3 > 0)
                {
                    Servers = new string[num3];
                    ClsIDs  = new Guid[num3];
                    for (int j = 0; j < num3; j++)
                    {
                        Servers[j] = strArray[j];
                        ClsIDs[j]  = guidArray2[j];
                    }
                }
                strArray   = null;
                guidArray2 = null;
            }
        }
コード例 #8
0
        public void ListAll(Guid catid,out OpcServers[] serverslist)
        {
            serverslist = null;
             Dispose();
             Guid guid = new Guid("13486D51-4821-11D2-A494-3CB306C10000");
             Type typeoflist = Type.GetTypeFromCLSID(guid);
             OPCListObj = Activator.CreateInstance(typeoflist);

             ifList = (IOPCServerList)OPCListObj;
             if (ifList == null)
            Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);

             ifList.EnumClassesOfCategories(1,ref catid,0,ref catid,out EnumObj);
             if (EnumObj == null)
            Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);

             ifEnum = (IEnumGUID)EnumObj;
             if (ifEnum == null)
            Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);

             int maxcount = 300;
             IntPtr ptrGuid = Marshal.AllocCoTaskMem(maxcount * 16);
             int count = 0;
             ifEnum.Next(maxcount,ptrGuid,out count);
             if (count < 1) { Marshal.FreeCoTaskMem(ptrGuid); return; }

             serverslist = new OpcServers[count];

             byte[] guidbin = new byte[16];
             int runGuid = (int)ptrGuid;
             for (int i = 0; i < count; i++) {
            serverslist[i] = new OpcServers();
            Marshal.Copy((IntPtr)runGuid,guidbin,0,16);
            serverslist[i].ClsID = new Guid(guidbin);
            ifList.GetClassDetails(ref serverslist[i].ClsID,
                              out serverslist[i].ProgID,out serverslist[i].ServerName);
            runGuid += 16;
            }

             Marshal.FreeCoTaskMem(ptrGuid);
             Dispose();
        }
コード例 #9
0
        /// <summary>
        /// Returns an enumerator to allow to determine available OPC servers.
        /// </summary>
        /// <param name="categories">OPC Server categories (OPCDA/OPCHDA etc.)</param>
        /// <returns>Enumerator to allow to determine available OPC servers.</returns>
        public IEnumerable <ServerDescription> GetEnumerator(params Guid[] categories)
        {
            IEnumGUID    enumerator    = null;
            IOPCEnumGUID opcEnumerator = null;

            try
            {
                var tmp = Guid.Empty;
                if (serverList2 != null)
                {
                    serverList2.EnumClassesOfCategories(
                        (uint)categories.Length,
                        categories,
                        0,
                        ref tmp,
                        out opcEnumerator);
                }
                else
                {
                    serverList.EnumClassesOfCategories(
                        (uint)categories.Length,
                        categories,
                        0,
                        ref tmp,
                        out enumerator);
                }

                while (true)
                {
                    var  res     = 0;
                    uint fetched = 0;
                    var  ids     = new Guid[1];
                    if (opcEnumerator != null)
                    {
                        res = opcEnumerator.Next((uint)ids.Length, ids, out fetched);
                    }
                    else if (enumerator != null)
                    {
                        res = enumerator.Next(1, ids, out fetched);
                    }
                    if (res > 1)
                    {
                        Marshal.ThrowExceptionForHR(res);
                    }
                    if (fetched == 0)
                    {
                        break;
                    }

                    var id = ids[0];
                    ServerDescription serverDescription;
                    try
                    {
                        string name;
                        string programId;
                        var    versionIndependentProgramId = string.Empty;
                        if (serverList2 != null)
                        {
                            serverList2.GetClassDetails(ref id, out programId, out name, out versionIndependentProgramId);
                        }
                        else
                        {
                            serverList.GetClassDetails(ref id, out programId, out name);
                        }
                        serverDescription = new ServerDescription(id, programId, versionIndependentProgramId, name);
                    }
                    catch (Exception e)
                    {
                        serverDescription = new ServerDescription(id, e);
                    }

                    yield return(serverDescription);
                }
            }
            finally
            {
                if (enumerator != null)
                {
                    Marshal.ReleaseComObject(enumerator);
                }
                if (opcEnumerator != null)
                {
                    Marshal.ReleaseComObject(opcEnumerator);
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// List all
        /// </summary>
        /// <param name="catid">Catid</param>
        public static OpcServerDefinition[] ListAll(Guid catid)
        {
            OpcServerDefinition[] serverslist = new OpcServerDefinition[0];
            object enumObj    = null;
            Type   typeOfList = Type.GetTypeFromCLSID(OpcServerListGuid);
            object listObj    = Activator.CreateInstance(typeOfList);

            try
            {
                IOPCServerList opcServerList = listObj as IOPCServerList;
                if (opcServerList == null)
                {
                    Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);
                }

                opcServerList.EnumClassesOfCategories(1, ref catid, 0, ref catid, out enumObj);
                if (enumObj == null)
                {
                    Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);
                }

                IEnumGUID ifEnum = enumObj as IEnumGUID;
                if (ifEnum == null)
                {
                    Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);
                }

                const int maxcount = 300;
                IntPtr    ptrGuid  = Marshal.AllocCoTaskMem(maxcount * 16);
                ifEnum.Next(maxcount, ptrGuid, out int count);
                if (count < 1)
                {
                    Marshal.FreeCoTaskMem(ptrGuid);
                    return(serverslist);
                }

                serverslist = new OpcServerDefinition[count];

                byte[] guidbin = new byte[16];
                int    runGuid = (int)ptrGuid;
                for (int i = 0; i < count; i++)
                {
                    serverslist[i] = new OpcServerDefinition();
                    Marshal.Copy((IntPtr)runGuid, guidbin, 0, 16);
                    serverslist[i].ClsID = new Guid(guidbin);
                    opcServerList.GetClassDetails(ref serverslist[i].ClsID,
                                                  out serverslist[i].ProgID, out serverslist[i].Name);
                    runGuid += 16;
                }

                Marshal.FreeCoTaskMem(ptrGuid);
            }
            finally
            {
                if (!(enumObj == null))
                {
                    Marshal.ReleaseComObject(enumObj);
                }
                if (!(listObj == null))
                {
                    Marshal.ReleaseComObject(listObj);
                }
            }
            return(serverslist);
        }