大家好,又见面了,我是你们的朋友全栈君。
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();
}
取消
评论
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/151317.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...