示例#1
0
        /// <summary>
        /// For VBA Clients we can use COM interop compatible types to return table as string array.
        /// </summary>
        /// <returns>An string array of all the entries in the Running Object Table.</returns>
        public string[] TableAsStringArray()
        {
            List <string>       itemsList = new List <string>();
            IBindCtx            ctx;
            IRunningObjectTable table;
            IEnumMoniker        mon;

            IMoniker[] lst = new IMoniker[1];
            RotNativeMethods.CreateBindCtx(0, out ctx);
            ctx.GetRunningObjectTable(out table);
            table.EnumRunning(out mon);
            while (mon.Next(1, lst, IntPtr.Zero) == 0)
            {
                string displayName;
                lst[0].GetDisplayName(ctx, lst[0], out displayName);
                itemsList.Add(displayName);
            }
            return(itemsList.ToArray());
        }
示例#2
0
        /// <summary>
        /// This is the equivalent of VBA's GetObject where one supplies a filename or other moniker to retrieve an interface pointer to object.
        /// </summary>
        /// <param name="sRotEntry"></param>
        /// <returns>A COM interface pointer to object in running object table specified by entry.</returns>
        public object GetObject(string sRotEntry)
        {
            Object              retVal = null;
            IBindCtx            ctx;
            IRunningObjectTable table;
            IEnumMoniker        mon;

            IMoniker[] lst = new IMoniker[1];
            RotNativeMethods.CreateBindCtx(0, out ctx);
            ctx.GetRunningObjectTable(out table);
            table.EnumRunning(out mon);
            while (mon.Next(1, lst, IntPtr.Zero) == 0)
            {
                string displayName;
                lst[0].GetDisplayName(ctx, lst[0], out displayName);
                if (displayName == sRotEntry)
                {
                    table.GetObject(lst[0], out retVal);
                }
            }
            return(retVal);
        }
示例#3
0
        public RotTableEntry[] DetailedTableAsArray()
        {
            List <RotTableEntry> itemsList = new List <RotTableEntry>();
            IBindCtx             ctx;
            IRunningObjectTable  table;
            IEnumMoniker         mon;

            IMoniker[] lst = new IMoniker[1];
            RotNativeMethods.CreateBindCtx(0, out ctx);
            ctx.GetRunningObjectTable(out table);
            table.EnumRunning(out mon);
            while (mon.Next(1, lst, IntPtr.Zero) == 0)
            {
                RotTableEntry item = new RotTableEntry();
                item.monikerDetails = new MonikerDetails();
                {
                    Guid guid;
                    lst[0].GetClassID(out guid);
                    item.monikerDetails.monikerClassId = RotNativeMethods.StringFromCLSID(guid);
                    switch (item.monikerDetails.monikerClassId)
                    {
                    case "{00000303-0000-0000-C000-000000000046}":
                        item.monikerDetails.monikerType = "FileMoniker";
                        break;

                    case "{00000304-0000-0000-C000-000000000046}":
                        item.monikerDetails.monikerType = "ItemMoniker";
                        break;

                    case "{00000305-0000-0000-C000-000000000046}":
                        item.monikerDetails.monikerType = "AntiMoniker";
                        break;

                    case "{00000306-0000-0000-C000-000000000046}":
                        item.monikerDetails.monikerType = "PointerMoniker";
                        break;

                    case "{00000308-0000-0000-C000-000000000046}":
                        item.monikerDetails.monikerType = "PackageMoniker";
                        break;

                    case "{00000309-0000-0000-C000-000000000046}":
                        item.monikerDetails.monikerType = "CompositeMoniker";
                        break;

                    case "{0000031A-0000-0000-C000-000000000046}":
                        item.monikerDetails.monikerType = "ClassMoniker";
                        break;

                    default:
                    {
                        RegistryKey monikerClassKey = Registry.ClassesRoot.OpenSubKey("CLSID\\" + item.monikerDetails.monikerClassId);
                        if (monikerClassKey == null)
                        {
                            item.monikerDetails.monikerType = "Failed to identify moniker";
                        }
                        else
                        {
                            item.monikerDetails.monikerType = monikerClassKey.GetValue(null).ToString();
                        }
                    }
                    break;
                    }
                }
                {
                    string displayName;
                    lst[0].GetDisplayName(ctx, lst[0], out displayName);
                    item.displayName = displayName;
                    item.className   = "";
                }
                {
                    if (item.monikerDetails.monikerType == "FileMoniker")
                    {
                        System.Runtime.InteropServices.ComTypes.FILETIME ft;
                        table.GetTimeOfLastChange(lst[0], out ft);
                        long     hFT2 = (((long)ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
                        DateTime dte  = DateTime.FromFileTime(hFT2);
                        item.lastChange = dte;
                        //http://snipplr.com/view/32409/
                    }
                    if (item.monikerDetails.monikerType == "ItemMoniker")
                    {
                        string coreGuid = "";
                        {
                            if (item.displayName.Substring(0, 1) == "!")
                            {
                                coreGuid = item.displayName.Substring(1, 38);
                                RegistryKey key = null;
                                key = Registry.ClassesRoot.OpenSubKey("CLSID\\" + coreGuid);
                                if (key == null)
                                {
                                    key = Registry.ClassesRoot.OpenSubKey("Wow6432Node\\CLSID\\" + coreGuid);
                                }
                                if (key != null)
                                {
                                    item.className = key.GetValue(null).ToString();
                                }
                            }
                        }
                    }
                }
                itemsList.Add(item);
            }
            return(itemsList.ToArray());
        }