Пример #1
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();
        }
Пример #2
0
 public void ListAllData20(out OpcServers[] serverslist)
 {
     // CATID_OPCDAServer20
      ListAll(new Guid("63D5F432-CFE4-11d1-B2C8-0060083BA1FB"),out serverslist);
 }
Пример #3
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();
        }