コード例 #1
0
ファイル: ComServer.cs プロジェクト: ravikp/rims.net
 internal static HRESULT DllGetClassObject(CLSID clsid, IID iid, out IntPtr ppunk)
 {
     if (iid != ComAPI.guidIClassFactory)
     {
         ppunk = IntPtr.Zero;
         return ComAPI.E_INVALIDARG;
     }
     foreach (ExcelComClassType comClass in registeredComClassTypes)
     {
        if (comClass.ClsId == clsid)
        {
            ClassFactory factory = new ClassFactory(comClass);
            IntPtr punkFactory = Marshal.GetIUnknownForObject(factory);
            HRESULT hrQI = Marshal.QueryInterface(punkFactory, ref iid, out ppunk);
            Marshal.Release(punkFactory);
            if (hrQI == ComAPI.S_OK)
            {
                return ComAPI.S_OK;
            }
            else
            {
                return ComAPI.E_UNEXPECTED;
            }
        }
     }
     ppunk = IntPtr.Zero;
     return ComAPI.CLASS_E_CLASSNOTAVAILABLE;
 }
コード例 #2
0
        public TaskbarItemInfo()
        {
            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                ITaskbarList taskbarList = null;
                try
                {
                    taskbarList = CLSID.CoCreateInstance <ITaskbarList>(CLSID.TaskbarList);
                    taskbarList.HrInit();

                    // This QI will only work on Win7.
                    _taskbarList = taskbarList as ITaskbarList3;

                    taskbarList = null;
                }
                finally
                {
                    Utility.SafeRelease(ref taskbarList);
                }

                _overlaySize = new Size(
                    NativeMethods.GetSystemMetrics(SM.CXSMICON),
                    NativeMethods.GetSystemMetrics(SM.CYSMICON));
            }

            // Set ThumbButtons to an empty list so callers can just use the property.
            ThumbButtonInfos = new ThumbButtonInfoCollection();
        }
コード例 #3
0
 internal static HRESULT DllGetClassObject(CLSID clsid, IID iid, out IntPtr ppunk)
 {
     if (iid != ComAPI.guidIClassFactory)
     {
         ppunk = IntPtr.Zero;
         return(ComAPI.E_INVALIDARG);
     }
     foreach (ExcelComClassType comClass in registeredComClassTypes)
     {
         if (comClass.ClsId == clsid)
         {
             ClassFactory factory     = new ClassFactory(comClass);
             IntPtr       punkFactory = Marshal.GetIUnknownForObject(factory);
             HRESULT      hrQI        = Marshal.QueryInterface(punkFactory, ref iid, out ppunk);
             Marshal.Release(punkFactory);
             if (hrQI == ComAPI.S_OK)
             {
                 return(ComAPI.S_OK);
             }
             else
             {
                 return(ComAPI.E_UNEXPECTED);
             }
         }
     }
     ppunk = IntPtr.Zero;
     return(ComAPI.CLASS_E_CLASSNOTAVAILABLE);
 }
コード例 #4
0
ファイル: ComServer.cs プロジェクト: xd91/ExcelDna
        internal static HRESULT DllGetClassObject(CLSID clsid, IID iid, out IntPtr ppunk)
        {
            if (iid != ComAPI.guidIClassFactory)
            {
                ppunk = IntPtr.Zero;
                return(ComAPI.E_INVALIDARG);
            }

            ComAPI.IClassFactory factory;
            if (registeredClassFactories.TryGetValue(clsid, out factory) ||
                TryGetComClassType(clsid, out factory))
            {
                IntPtr  punkFactory = Marshal.GetIUnknownForObject(factory);
                HRESULT hrQI        = Marshal.QueryInterface(punkFactory, ref iid, out ppunk);
                Marshal.Release(punkFactory);
                if (hrQI == ComAPI.S_OK)
                {
                    return(ComAPI.S_OK);
                }
                else
                {
                    return(ComAPI.E_UNEXPECTED);
                }
            }

            // Otherwise it was not found
            ppunk = IntPtr.Zero;
            return(ComAPI.CLASS_E_CLASSNOTAVAILABLE);
        }
コード例 #5
0
ファイル: ComServer.cs プロジェクト: gjvdkamp/ExcelDna
        internal static HRESULT DllGetClassObject(CLSID clsid, IID iid, out IntPtr ppunk)
        {
            if (iid != ComAPI.guidIClassFactory)
            {
                ppunk = IntPtr.Zero;
                return ComAPI.E_INVALIDARG;
            }

            ComAPI.IClassFactory factory;
            if (registeredClassFactories.TryGetValue(clsid, out factory) ||
                TryGetComClassType(clsid, out factory))
            {
                IntPtr punkFactory = Marshal.GetIUnknownForObject(factory);
                HRESULT hrQI = Marshal.QueryInterface(punkFactory, ref iid, out ppunk);
                Marshal.Release(punkFactory);
                if (hrQI == ComAPI.S_OK)
                {
                    return ComAPI.S_OK;
                }
                else
                {
                    return ComAPI.E_UNEXPECTED;
                }
            }

            // Otherwise it was not found
            ppunk = IntPtr.Zero;
            return ComAPI.CLASS_E_CLASSNOTAVAILABLE;
        }
コード例 #6
0
 internal static HRESULT DllGetClassObject(CLSID clsid, IID iid, out IntPtr ppunk)
 //internal static HRESULT DllGetClassObject(ref Guid clsid, ref Guid iid, out object ppunk)
 {
     HRESULT result;
     object[] args = new object[] {clsid, iid, null};
     result = (HRESULT)integrationType.InvokeMember("DllGetClassObject", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, args);
     ppunk = (IntPtr)args[2];
     return result;
 }
コード例 #7
0
ファイル: XlAddIn.cs プロジェクト: cezary12/ExcelDna
        internal static HRESULT DllGetClassObject(CLSID clsid, IID iid, out IntPtr ppunk)
        {
            Debug.Print("DllGetClassObject reached!!");
            // IntPtr pout;
            HRESULT result;

            InitializeIntegration();
            result = IntegrationHelpers.DllGetClassObject(clsid, iid, out ppunk);
            return(result);
        }
コード例 #8
0
        internal static HRESULT DllGetClassObject(CLSID clsid, IID iid, out IntPtr ppunk)
        {
            Debug.Print("DllGetClassObject entered - calling InitializeIntegration.");
            HRESULT result;

            InitializeIntegration();
            Logger.Initialization.Verbose("In DllGetClassObject");
            result = ExcelIntegration.DllGetClassObject(clsid, iid, out ppunk);
            return(result);
        }
コード例 #9
0
        internal static HRESULT DllGetClassObject(CLSID clsid, IID iid, out IntPtr ppunk)
        //internal static HRESULT DllGetClassObject(ref Guid clsid, ref Guid iid, out object ppunk)
        {
            HRESULT result;

            object[] args = new object[] { clsid, iid, null };
            result = (HRESULT)integrationType.InvokeMember("DllGetClassObject", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, args);
            ppunk  = (IntPtr)args[2];
            return(result);
        }
コード例 #10
0
            public static TypeLib GetTypeLib(CLSID clsid)
            {
                string version = "1.0";

                if (clsid.Version != null)
                {
                    version = clsid.Version;
                }

                return(GetTypeLib(clsid.TypeLib, version));
            }
コード例 #11
0
 /// <summary>
 /// Converts the object to a displayable string.
 /// </summary>
 public override string ToString()
 {
     if (!String.IsNullOrEmpty(ProgId))
     {
         return(ProgId);
     }
     if (CLSID == Guid.Empty)
     {
         return("(unknown)");
     }
     return(CLSID.ToString());
 }
コード例 #12
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <param name="other">An object to compare with this object.</param>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.
 /// </returns>
 public bool Equals(OpcServerDescription other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(CLSID.Equals(other.CLSID));
 }
コード例 #13
0
 private void ValidateCLSID(CLSID actual)
 {
     Assert.IsNotNull(actual);
     AssertExtensions.IsNotEmpty(actual.Guid);
     AssertExtensions.IsNotEmpty(actual.Name);
     //AssertExtensions.IsNotEmpty(actual.LocalServer32); //optional
     //AssertExtensions.IsNotEmpty(actual.InProcServer32); //optional
     AssertExtensions.IsNotEmpty(actual.ProgID);
     AssertExtensions.IsNotEmpty(actual.TypeLib);
     AssertExtensions.IsNotEmpty(actual.VersionIndependentProgID);
     //AssertExtensions.IsNotEmpty(actual.Version); //optional
 }
コード例 #14
0
ファイル: ComServer.cs プロジェクト: xd91/ExcelDna
 static bool TryGetComClassType(CLSID clsId, out ComAPI.IClassFactory factory)
 {
     // Check among the persistently registered classes
     foreach (ExcelComClassType comClass in registeredComClassTypes)
     {
         if (comClass.ClsId == clsId)
         {
             factory = new ClassFactory(comClass);
             return(true);
         }
     }
     factory = null;
     return(false);
 }
コード例 #15
0
            public static CLSID GetCLSID(string guid)
            {
                CLSID result = new CLSID();

                result.Guid = guid;
                if (result.Guid == null)
                {
                    return(null);
                }
                result.Name = RegistryManipulator.GetKeyDefaultValue("HKEY_CLASSES_ROOT\\Wow6432Node\\CLSID\\" + guid);
                if (result.Name == null)
                {
                    return(null);
                }
                result.LocalServer32 = RegistryManipulator.GetKeyDefaultValue("HKEY_CLASSES_ROOT\\Wow6432Node\\CLSID\\" + guid + "\\LocalServer32");
                //if (result.LocalServer32 == null)
                //  return null;
                result.InProcServer32 = RegistryManipulator.GetKeyDefaultValue("HKEY_CLASSES_ROOT\\Wow6432Node\\CLSID\\" + guid + "\\InProcServer32");
                //if (result.InProcServer32 == null)
                //  return null;
                result.ProgID = RegistryManipulator.GetKeyDefaultValue("HKEY_CLASSES_ROOT\\Wow6432Node\\CLSID\\" + guid + "\\ProgID");
                if (result.ProgID == null)
                {
                    return(null);
                }
                result.TypeLib = RegistryManipulator.GetKeyDefaultValue("HKEY_CLASSES_ROOT\\Wow6432Node\\CLSID\\" + guid + "\\TypeLib");
                if (result.TypeLib == null)
                {
                    return(null);
                }
                result.VersionIndependentProgID = RegistryManipulator.GetKeyDefaultValue("HKEY_CLASSES_ROOT\\Wow6432Node\\CLSID\\" + guid + "\\TypeLib");
                if (result.VersionIndependentProgID == null)
                {
                    return(null);
                }
                result.Version = RegistryManipulator.GetKeyDefaultValue("HKEY_CLASSES_ROOT\\Wow6432Node\\CLSID\\" + guid + "\\Version");
                //if (result.Version == null)
                //  return null;

                //success
                return(result);
            }
コード例 #16
0
 public TaskbarItemInfo()
 {
     if (!DesignerProperties.GetIsInDesignMode(this))
     {
         ITaskbarList taskbarList = null;
         try
         {
             taskbarList = CLSID.CoCreateInstance <ITaskbarList>("56FDF344-FD6D-11d0-958A-006097C9A090");
             taskbarList.HrInit();
             this._taskbarList = (taskbarList as ITaskbarList3);
             taskbarList       = null;
         }
         finally
         {
             Utility.SafeRelease <ITaskbarList>(ref taskbarList);
         }
         this._overlaySize = new Size((double)NativeMethods.GetSystemMetrics(SM.CXSMICON), (double)NativeMethods.GetSystemMetrics(SM.CYSMICON));
     }
     this.ThumbButtonInfos = new ThumbButtonInfoCollection();
 }
コード例 #17
0
        public TaskbarItemInfo()
        {
            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                ITaskbarList taskbarList = null;
                try
                {
                    taskbarList = CLSID.CoCreateInstance <ITaskbarList>(CLSID.TaskbarList);
                    taskbarList.HrInit();

                    _taskbarList = taskbarList as ITaskbarList3;
                    taskbarList  = null;
                }
                finally
                {
                    Utility.SafeRelease(ref taskbarList);
                }
                _overlaySize = new Size(NativeMethods.GetSystemMetrics(SM.CXSMICON), NativeMethods.GetSystemMetrics(SM.CYSMICON));
            }

            ThumbButtonInfos = new ThumbButtonInfoCollection();
        }
コード例 #18
0
ファイル: ComServer.cs プロジェクト: xd91/ExcelDna
 internal static void RegisterClassFactory(CLSID clsId, ComAPI.IClassFactory classFactory)
 {
     // CONSIDER: Do we need to deal with the case where it is already in the list?
     //           For now we expect it to throw...
     registeredClassFactories.Add(clsId, classFactory);
 }
コード例 #19
0
ファイル: JumpList.cs プロジェクト: zhouweiaccp/gitscc
        private void _BuildShellLists(out List <JumpItem> successList, out List <_RejectedJumpItemPair> rejectedList, out List <_ShellObjectPair> removedList)
        {
            // Declare these outside the try block so we can cleanup native resources in the _ShellObjectPairs.
            List <List <_ShellObjectPair> > categories = null;

            removedList = null;
            ICustomDestinationList destinationList = CLSID.CoCreateInstance <ICustomDestinationList>(CLSID.DestinationList);

            try
            {
                // Even though we're not exposing Shell's AppModelId concept, we'll still respect it
                // since it's easy to clients to p/invoke to set it for Application and Window, but not for JumpLists
                string appId = _RuntimeId;
                if (!string.IsNullOrEmpty(appId))
                {
                    destinationList.SetAppID(appId);
                }

                // The number ot items visible on a jump list is a user setting.  Shell doesn't reject items based on overflow.
                // We don't bother checking against it because the app can query the setting and manage overflow based on it
                // if they really care.  We'll happily add too many items with the hope that if the user changes the setting
                // items will be recovered from the overflow.
                uint slotsVisible;
                Guid removedIid     = new Guid(IID.ObjectArray);
                var  objectsRemoved = (IObjectArray)destinationList.BeginList(out slotsVisible, ref removedIid);

                // Keep track of the items that were previously removed by the user.
                // We don't want to pend any items that are contained in this list.
                // It's possible that this contains null JumpItems when we were unable to do the conversion.
                removedList = GenerateJumpItems(objectsRemoved);

                // Keep track of the items that have been successfully pended.
                // IMPORTANT: Ensure at the end of this that if the list is applied again that it would
                //     result in items being added to the JumpList in the same order.
                //     This doesn't mean that they'll be ordered the same as how the user added them
                //     (e.g. categories will be coalesced), but the categories should appear in the same order.
                //     Since when we call AddCategory we're doing it in reverse order, AddCategory augments
                //     the items in the list in reverse as well.  At the end the final list is reversed.
                successList = new List <JumpItem>(JumpItems.Count);

                // Keep track of the items that we couldn't pend, and why.
                rejectedList = new List <_RejectedJumpItemPair>(JumpItems.Count);

                // Need to group the JumpItems based on their categories.
                // The special "Tasks" category doesn't actually have a name and should be first so it's unconditionally added.
                categories = new List <List <_ShellObjectPair> >()
                {
                    new List <_ShellObjectPair>()
                };

                // This is not thread-safe.
                // We're traversing the original list so we're vulnerable to another thread modifying it during the enumeration.
                foreach (var jumpItem in JumpItems)
                {
                    if (jumpItem == null)
                    {
                        // App added a null jump item?  Just go through the normal failure mechanisms.
                        rejectedList.Add(new _RejectedJumpItemPair {
                            JumpItem = jumpItem, Reason = JumpItemRejectionReason.InvalidItem
                        });
                        continue;
                    }

                    object shellObject = null;
                    try
                    {
                        shellObject = GetShellObjectForJumpItem(jumpItem);
                        // If for some reason we couldn't create the item add it to the rejected list.
                        if (shellObject == null)
                        {
                            rejectedList.Add(new _RejectedJumpItemPair {
                                Reason = JumpItemRejectionReason.InvalidItem, JumpItem = jumpItem
                            });
                            continue;
                        }

                        // Don't add this item if it's in the list of items previously removed by the user.
                        if (ListContainsShellObject(removedList, shellObject))
                        {
                            rejectedList.Add(new _RejectedJumpItemPair {
                                Reason = JumpItemRejectionReason.RemovedByUser, JumpItem = jumpItem
                            });
                            continue;
                        }

                        var shellMap = new _ShellObjectPair {
                            JumpItem = jumpItem, ShellObject = shellObject
                        };
                        if (string.IsNullOrEmpty(jumpItem.CustomCategory))
                        {
                            // No custom category, so add to the Tasks list.
                            categories[0].Add(shellMap);
                        }
                        else
                        {
                            // Find the appropriate category and add to that list.
                            // If it doesn't exist, add a new category for it.
                            bool categoryExists = false;
                            foreach (var list in categories)
                            {
                                // The first item in the category list can be used to check the name.
                                if (list.Count > 0 && list[0].JumpItem.CustomCategory == jumpItem.CustomCategory)
                                {
                                    list.Add(shellMap);
                                    categoryExists = true;
                                    break;
                                }
                            }
                            if (!categoryExists)
                            {
                                categories.Add(new List <_ShellObjectPair>()
                                {
                                    shellMap
                                });
                            }
                        }

                        // Shell interface is now owned by the category list.
                        shellObject = null;
                    }
                    finally
                    {
                        Utility.SafeRelease(ref shellObject);
                    }
                }

                // Jump List categories get added top-down, except for "Tasks" which is special and always at the bottom.
                // We want the Recent/Frequent to always be at the top so they get added first.
                // Logically the categories are added bottom-up, but their contents are top-down,
                // so we reverse the order we add the categories to the destinationList.
                // To preserve the item ordering AddCategory also adds items in reverse.
                // We need to reverse the final list when everything is done.
                categories.Reverse();

                if (ShowFrequentCategory)
                {
                    destinationList.AppendKnownCategory(KDC.FREQUENT);
                }

                if (ShowRecentCategory)
                {
                    destinationList.AppendKnownCategory(KDC.RECENT);
                }

                // Now that all the JumpItems are grouped add them to the custom destinations list.
                foreach (List <_ShellObjectPair> categoryList in categories)
                {
                    if (categoryList.Count > 0)
                    {
                        string categoryHeader = categoryList[0].JumpItem.CustomCategory;
                        AddCategory(destinationList, categoryHeader, categoryList, successList, rejectedList);
                    }
                }

                destinationList.CommitList();

                // Swap the current list with what we were able to successfully place into the JumpList.
                // Reverse it first to ensure that the items are in a repeatable order.
                successList.Reverse();
            }
            finally
            {
                // Deterministically release native resources.

                Utility.SafeRelease(ref destinationList);

                if (categories != null)
                {
                    foreach (List <_ShellObjectPair> list in categories)
                    {
                        _ShellObjectPair.ReleaseShellObjects(list);
                    }
                }

                // Note that this only clears the ShellObjects, not the JumpItems.
                // We still need the JumpItems out of this list for the JumpItemsRemovedByUser event.
                _ShellObjectPair.ReleaseShellObjects(removedList);
            }
        }
コード例 #20
0
ファイル: ComServer.cs プロジェクト: gjvdkamp/ExcelDna
 internal static void UnregisterClassFactory(CLSID clsId)
 {
     registeredClassFactories.Remove(clsId);
 }
コード例 #21
0
ファイル: JumpList.cs プロジェクト: Yerongn/HandyControl
        private void _BuildShellLists(out List <JumpItem> successList, out List <JumpList._RejectedJumpItemPair> rejectedList, out List <JumpList._ShellObjectPair> removedList)
        {
            List <List <JumpList._ShellObjectPair> > list = null;

            removedList = null;
            ICustomDestinationList customDestinationList = CLSID.CoCreateInstance <ICustomDestinationList>("77f10cf0-3db5-4966-b520-b7c54fd35ed6");

            try
            {
                string runtimeId = JumpList._RuntimeId;
                if (!string.IsNullOrEmpty(runtimeId))
                {
                    customDestinationList.SetAppID(runtimeId);
                }
                Guid         guid = new Guid("92CA9DCD-5622-4bba-A805-5E9F541BD8C9");
                uint         num;
                IObjectArray shellObjects = (IObjectArray)customDestinationList.BeginList(out num, ref guid);
                removedList  = JumpList.GenerateJumpItems(shellObjects);
                successList  = new List <JumpItem>(this.JumpItems.Count);
                rejectedList = new List <JumpList._RejectedJumpItemPair>(this.JumpItems.Count);
                list         = new List <List <JumpList._ShellObjectPair> >
                {
                    new List <JumpList._ShellObjectPair>()
                };
                foreach (JumpItem jumpItem in this.JumpItems)
                {
                    if (jumpItem == null)
                    {
                        rejectedList.Add(new JumpList._RejectedJumpItemPair
                        {
                            JumpItem = jumpItem,
                            Reason   = JumpItemRejectionReason.InvalidItem
                        });
                    }
                    else
                    {
                        object obj = null;
                        try
                        {
                            obj = JumpList.GetShellObjectForJumpItem(jumpItem);
                            if (obj == null)
                            {
                                rejectedList.Add(new JumpList._RejectedJumpItemPair
                                {
                                    Reason   = JumpItemRejectionReason.InvalidItem,
                                    JumpItem = jumpItem
                                });
                            }
                            else if (JumpList.ListContainsShellObject(removedList, obj))
                            {
                                rejectedList.Add(new JumpList._RejectedJumpItemPair
                                {
                                    Reason   = JumpItemRejectionReason.RemovedByUser,
                                    JumpItem = jumpItem
                                });
                            }
                            else
                            {
                                JumpList._ShellObjectPair item = new JumpList._ShellObjectPair
                                {
                                    JumpItem    = jumpItem,
                                    ShellObject = obj
                                };
                                if (string.IsNullOrEmpty(jumpItem.CustomCategory))
                                {
                                    list[0].Add(item);
                                }
                                else
                                {
                                    bool flag = false;
                                    foreach (List <JumpList._ShellObjectPair> list2 in list)
                                    {
                                        if (list2.Count > 0 && list2[0].JumpItem.CustomCategory == jumpItem.CustomCategory)
                                        {
                                            list2.Add(item);
                                            flag = true;
                                            break;
                                        }
                                    }
                                    if (!flag)
                                    {
                                        list.Add(new List <JumpList._ShellObjectPair>
                                        {
                                            item
                                        });
                                    }
                                }
                                obj = null;
                            }
                        }
                        finally
                        {
                            Utility.SafeRelease <object>(ref obj);
                        }
                    }
                }
                list.Reverse();
                if (this.ShowFrequentCategory)
                {
                    customDestinationList.AppendKnownCategory(KDC.FREQUENT);
                }
                if (this.ShowRecentCategory)
                {
                    customDestinationList.AppendKnownCategory(KDC.RECENT);
                }
                foreach (List <JumpList._ShellObjectPair> list3 in list)
                {
                    if (list3.Count > 0)
                    {
                        string customCategory = list3[0].JumpItem.CustomCategory;
                        JumpList.AddCategory(customDestinationList, customCategory, list3, successList, rejectedList);
                    }
                }
                customDestinationList.CommitList();
                successList.Reverse();
            }
            finally
            {
                Utility.SafeRelease <ICustomDestinationList>(ref customDestinationList);
                if (list != null)
                {
                    foreach (List <JumpList._ShellObjectPair> list4 in list)
                    {
                        JumpList._ShellObjectPair.ReleaseShellObjects(list4);
                    }
                }
                JumpList._ShellObjectPair.ReleaseShellObjects(removedList);
            }
        }
コード例 #22
0
ファイル: GetStatus.cs プロジェクト: themccrady/ODSyncService
        protected override void ProcessRecord()
        {
            if (!Environment.UserInteractive)
                throw new InvalidOperationException("Non-Interactive mode detected. OneDrive Status can only be checked interactively");
            if (UacHelper.IsProcessElevated)
                throw new InvalidOperationException("PowerShell is running in Administrator mode. OneDrive status cannot be checked in elevated privileges");
            WriteLog.ShouldLog = IncludeLog;
            if (IncludeLog)
                WriteVerbose("Log file is being saved @ "+WriteLog.FileName);
            if (dllPath == null)
            {
                CopyDLL();
            }

            OdSyncStatusWS os = new OdSyncStatusWS();
            List<StatusDetail> statuses = new List<StatusDetail>();

            // Just Get the Path
            if(!String.IsNullOrEmpty(ByPath))
            {
                if(CLSID == Guid.Empty)
                    WriteObject(os.GetStatus(ByPath).ToString());
                else
                {

                    WriteObject(Native.API.IsCertainType(ByPath, CLSID));
                }
                return;
                
            }
            var statusCol = os.GetStatus();
            foreach(var status in statusCol)
            {
                if (String.IsNullOrEmpty(Type) || status.ServiceType.ToLower().Contains(Type.ToLower().Replace("*", "")))
                {
                    if(CLSID != Guid.Empty)
                    {
                        status.StatusString = Native.API.IsCertainType(status.LocalPath, CLSID) ? "GuidFound "+CLSID.ToString("B") : "GuidNotFound " + CLSID.ToString("B");
                    }
                    statuses.Add(status);

                }

            }
            WriteObject(statuses.ToArray());

        }
コード例 #23
0
        private void _BuildShellLists(out List <JumpItem> successList, out List <_RejectedJumpItemPair> rejectedList, out List <_ShellObjectPair> removedList)
        {
            List <List <_ShellObjectPair> > categories = null;

            removedList = null;
            var destinationList = CLSID.CoCreateInstance <ICustomDestinationList>(CLSID.DestinationList);

            try
            {
                var appId = _RuntimeId;
                if (!string.IsNullOrEmpty(appId))
                {
                    destinationList.SetAppID(appId);
                }

                uint slotsVisible;
                var  removedIid     = new Guid(IID.ObjectArray);
                var  objectsRemoved = (IObjectArray)destinationList.BeginList(out slotsVisible, ref removedIid);

                removedList = GenerateJumpItems(objectsRemoved);

                successList = new List <JumpItem>(JumpItems.Count);

                rejectedList = new List <_RejectedJumpItemPair>(JumpItems.Count);

                categories = new List <List <_ShellObjectPair> > {
                    new List <_ShellObjectPair>()
                };

                foreach (var jumpItem in JumpItems)
                {
                    if (jumpItem == null)
                    {
                        rejectedList.Add(new _RejectedJumpItemPair {
                            JumpItem = jumpItem, Reason = JumpItemRejectionReason.InvalidItem
                        });
                        continue;
                    }
                    object shellObject = null;
                    try
                    {
                        shellObject = GetShellObjectForJumpItem(jumpItem);

                        if (shellObject == null)
                        {
                            rejectedList.Add(new _RejectedJumpItemPair {
                                Reason = JumpItemRejectionReason.InvalidItem, JumpItem = jumpItem
                            });
                            continue;
                        }

                        if (ListContainsShellObject(removedList, shellObject))
                        {
                            rejectedList.Add(new _RejectedJumpItemPair {
                                Reason = JumpItemRejectionReason.RemovedByUser, JumpItem = jumpItem
                            });
                            continue;
                        }
                        var shellMap = new _ShellObjectPair {
                            JumpItem = jumpItem, ShellObject = shellObject
                        };
                        if (string.IsNullOrEmpty(jumpItem.CustomCategory))
                        {
                            categories[0].Add(shellMap);
                        }
                        else
                        {
                            var categoryExists = false;
                            foreach (var list in categories)
                            {
                                if (list.Count > 0 && list[0].JumpItem.CustomCategory == jumpItem.CustomCategory)
                                {
                                    list.Add(shellMap);
                                    categoryExists = true;
                                    break;
                                }
                            }
                            if (!categoryExists)
                            {
                                categories.Add(new List <_ShellObjectPair> {
                                    shellMap
                                });
                            }
                        }

                        shellObject = null;
                    }
                    finally
                    {
                        Utility.SafeRelease(ref shellObject);
                    }
                }

                categories.Reverse();
                if (ShowFrequentCategory)
                {
                    destinationList.AppendKnownCategory(KDC.FREQUENT);
                }
                if (ShowRecentCategory)
                {
                    destinationList.AppendKnownCategory(KDC.RECENT);
                }

                foreach (var categoryList in categories)
                {
                    if (categoryList.Count > 0)
                    {
                        var categoryHeader = categoryList[0].JumpItem.CustomCategory;
                        AddCategory(destinationList, categoryHeader, categoryList, successList, rejectedList);
                    }
                }
                destinationList.CommitList();

                successList.Reverse();
            }
            finally
            {
                Utility.SafeRelease(ref destinationList);
                if (categories != null)
                {
                    foreach (var list in categories)
                    {
                        _ShellObjectPair.ReleaseShellObjects(list);
                    }
                }

                _ShellObjectPair.ReleaseShellObjects(removedList);
            }
        }
コード例 #24
0
 /// <summary>
 /// Returns a hash code for this instance.
 /// </summary>
 /// <returns>
 /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
 /// </returns>
 public override int GetHashCode()
 {
     return(CLSID.GetHashCode());
 }
コード例 #25
0
        /// <summary>
        /// Registers this instance as a COM server with the specified CLSID.
        /// </summary>
        public void Register()
        {
            DotNetOpcServer _server = new DotNetOpcServer(ServerCLSID);

            if (_server.Specifications == Specifications.None)
            {
                throw new ApplicationException("The .NET server does not implement any OPC specifications.");
            }
            DotNetOpcServerWrapper _wrapper = new DotNetOpcServerWrapper(WrapperCLSID);

            if (_wrapper.Specifications == Specifications.None)
            {
                throw new ApplicationException("The .NET server wrapper does not implement any OPC interfaces.");
            }
            // determine the intersection of between the specs supported by the wrapper and the specs supported by the server.
            Specifications specifications = _wrapper.Specifications & _server.Specifications;

            if (specifications == Specifications.None)
            {
                throw new ApplicationException("The .NET server wrapper does not implement any OPC interfaces supported by the .NET server.");
            }
            // verify url and prog id.
            string _progId = ProgId;

            if (WrapperCLSID == Guid.Empty || String.IsNullOrEmpty(_progId))
            {
                throw new ApplicationException("Proxy does not have a valid wrapper clsid or prog id.");
            }
            // verify wrapper path.
            string _wrapperPath = WrapperCLSID.GetExecutablePath();

            if (_wrapperPath == null)
            {
                throw new ApplicationException("OPC server wrapper is not registered on this machine.");
            }
            // remove existing CLSID.
            Guid _existingClsid = Utils.CLSIDFromProgID(_progId);

            if (_existingClsid != CLSID)
            {
                Utils.UnregisterComServer(_existingClsid);
            }
            string _CLSIDKey = String.Format(@"CLSID\{{{0}}}", CLSID.ToString().ToUpper());
            // create new entries.
            RegistryKey _key = Registry.ClassesRoot.CreateSubKey(_CLSIDKey);

            if (_key == null)
            {
                throw new ApplicationException("Could not create key: " + _CLSIDKey);
            }
            // save description.
            if (String.IsNullOrEmpty(m_description))
            {
                m_description = _progId;
            }
            _key.SetValue(null, m_description);
            try
            {
                // create local server key.
                RegistryKey _subkey = _key.CreateSubKey("LocalServer32");
                if (_subkey == null)
                {
                    throw new ApplicationException("Could not create key: LocalServer32");
                }
                _subkey.SetValue(null, _wrapperPath);
                _subkey.SetValue("WrapperClsid", String.Format("{{{0}}}", WrapperCLSID));
                _subkey.Close();
                // create prog id key.
                _subkey = _key.CreateSubKey("ProgId");
                if (_subkey == null)
                {
                    throw new ApplicationException("Could not create key: ProgId");
                }
                _subkey.SetValue(null, _progId);
                _subkey.Close();
                // create endpoint key.
                _subkey = _key.CreateSubKey(WrappedServerSubKey);
                if (_subkey == null)
                {
                    throw new ApplicationException("Could not create key: " + WrappedServerSubKey);
                }
                // add parameters.
                try
                {
                    _subkey.SetValue(null, String.Format("{{{0}}}", ServerCLSID));
                    // remove unused parameters.
                    foreach (string name in _subkey.GetValueNames())
                    {
                        if (!String.IsNullOrEmpty(name) && !m_parameters.ContainsKey(name))
                        {
                            _subkey.DeleteValue(name, false);
                        }
                    }
                    // add new parameters.
                    foreach (KeyValuePair <string, string> entry in m_parameters)
                    {
                        if (!String.IsNullOrEmpty(entry.Key))
                        {
                            _subkey.SetValue(entry.Key, entry.Value);
                        }
                    }
                }
                finally
                {
                    _subkey.Close();
                }
            }
            finally
            {
                _key.Close();
            }
            // create prog id key.
            _key = Registry.ClassesRoot.CreateSubKey(_progId);
            if (_key == null)
            {
                throw new ApplicationException("Could not create key: " + _progId);
            }
            try
            {
                // create clsid key.
                RegistryKey _subkey = _key.CreateSubKey("CLSID");
                if (_subkey == null)
                {
                    throw new ApplicationException("Could not create key: CLSID");
                }
                _subkey.SetValue(null, String.Format("{{{0}}}", CLSID.ToString().ToUpper()));
                _subkey.Close();
                // create the OPC key use with DA 2.0 servers.
                if ((specifications & Specifications.DA2) != 0)
                {
                    _subkey = _key.CreateSubKey("OPC");
                    if (_subkey == null)
                    {
                        throw new ApplicationException("Could not create key: OPC");
                    }
                    _subkey.Close();
                }
            }
            finally
            {
                _key.Close();
            }
            // register as wrapper server.
            Utils.RegisterClassInCategory(CLSID, CommonDefinitions.CATID_RegisteredDotNetOpcServers, "OPC Wrapped COM Server Proxy");
            // register in OPC component categories.
            if ((specifications & Specifications.DA2) != 0)
            {
                Utils.RegisterClassInCategory(CLSID, typeof(OpcRcw.Da.CATID_OPCDAServer20).GUID);
            }
            if ((specifications & Specifications.DA3) != 0)
            {
                Utils.RegisterClassInCategory(CLSID, typeof(OpcRcw.Da.CATID_OPCDAServer30).GUID);
            }
            if ((specifications & Specifications.AE) != 0)
            {
                Utils.RegisterClassInCategory(CLSID, typeof(OpcRcw.Ae.CATID_OPCAEServer10).GUID);
            }
            if ((specifications & Specifications.HDA) != 0)
            {
                Utils.RegisterClassInCategory(CLSID, typeof(OpcRcw.Hda.CATID_OPCHDAServer10).GUID);
            }
        }
コード例 #26
0
ファイル: ComServer.cs プロジェクト: gjvdkamp/ExcelDna
 static bool TryGetComClassType(CLSID clsId, out ComAPI.IClassFactory factory)
 {
     // Check among the persistently registered classes
     foreach (ExcelComClassType comClass in registeredComClassTypes)
     {
         if (comClass.ClsId == clsId)
         {
             factory = new ClassFactory(comClass);
             return true;
         }
     }
     factory = null;
     return false;
 }
コード例 #27
0
ファイル: ComServer.cs プロジェクト: xd91/ExcelDna
 internal static void UnregisterClassFactory(CLSID clsId)
 {
     registeredClassFactories.Remove(clsId);
 }
コード例 #28
0
        protected override void PerformAction(object parameter)
        {
            var album = parameter as FacebookPhotoAlbum;

            if (album == null)
            {
                return;
            }

            string folderPath = null;

            if (Utility.IsOSVistaOrNewer)
            {
                IFileOpenDialog pFolderDialog = null;
                try
                {
                    pFolderDialog = CLSID.CoCreateInstance <IFileOpenDialog>(CLSID.FileOpenDialog);
                    pFolderDialog.SetOptions(pFolderDialog.GetOptions() | FOS.NOREADONLYRETURN | FOS.PICKFOLDERS);
                    pFolderDialog.SetTitle(string.Format("Select where to save \"{0}\"", album.Title));
                    pFolderDialog.SetOkButtonLabel("Save Album");

                    HRESULT hr = pFolderDialog.Show(new WindowInteropHelper(Application.Current.MainWindow).Handle);
                    if (hr.Failed)
                    {
                        return;
                    }

                    IShellItem pItem = null;
                    try
                    {
                        pItem      = pFolderDialog.GetResult();
                        folderPath = ShellUtil.GetPathFromShellItem(pItem);
                    }
                    finally
                    {
                        Utility.SafeRelease(ref pItem);
                    }
                }
                finally
                {
                    Utility.SafeRelease(ref pFolderDialog);
                }
            }
            else
            {
                var folderDialog = new System.Windows.Forms.FolderBrowserDialog
                {
                    Description         = "Choose where to save the album.",
                    ShowNewFolderButton = true,
                };
                if (folderDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                folderPath = folderDialog.SelectedPath;
            }

            album.SaveToFolder(folderPath, _OnAlbumSaveProgressCallback, null);
            Process.Start(new ProcessStartInfo {
                FileName = folderPath
            });
        }
コード例 #29
0
        // private bool disposedValue;

        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            if (!Environment.UserInteractive && ParameterSetName != OnDemandString)
            {
                throw new InvalidOperationException("Non-Interactive mode detected. OneDrive Status can only be checked interactively unless -OnDemandOnly is specified");
            }
            if (UacHelper.IsProcessElevated && ParameterSetName != OnDemandString)
            {
                throw new InvalidOperationException("PowerShell is running in Administrator mode. OneDrive status cannot be checked in elevated privileges");
            }
            OdSyncStatusWS.OnDemandOnly = onDemandOnly;
            WriteLog.ShouldLog          = includeLog;
            if (includeLog)
            {
                WriteVerbose("Log file is being saved @ " + WriteLog.FileName);
            }
            if (onDemandOnly)
            {
                WriteVerbose("On Demand Only check");
                WriteLog.WriteInformationEvent("On Demand Only option selected");
            }
            if (showDllPath)
            {
                WriteVerbose("Show DLL folder is enabled");
            }
            if (dllPath == null)
            {
                CopyDLL();
            }

            if (showDllPath)
            {
                Host.UI.WriteLine($"The temporary DLL path is '{Path.Combine(dllPath, dllName)}'");
            }
            OdSyncStatusWS      os       = new OdSyncStatusWS();
            List <StatusDetail> statuses = new List <StatusDetail>();

            // Just Get the Path
            if (!String.IsNullOrEmpty(ByPath))
            {
                WriteLog.WriteInformationEvent($"Path being tested is '{ByPath}'");
                if (CLSID == Guid.Empty)
                {
                    WriteObject(os.GetStatus(ByPath).ToString());
                }
                else
                {
                    WriteObject(Native.API.IsCertainType(ByPath, CLSID));
                }
                return;
            }
            var statusCol = os.GetStatus();

            foreach (var status in statusCol)
            {
                if (String.IsNullOrEmpty(Type) || status.ServiceType.ToLower().Contains(Type.ToLower().Replace("*", "")))
                {
                    WriteLog.WriteInformationEvent($"Guid Type being tested is '{CLSID}'");
                    if (CLSID != Guid.Empty)
                    {
                        status.StatusString = Native.API.IsCertainType(status.LocalPath, CLSID) ? "GuidFound " + CLSID.ToString("B") : "GuidNotFound " + CLSID.ToString("B");
                    }
                    statuses.Add(status);
                }
            }
            WriteObject(statuses.ToArray());
        }
コード例 #30
0
        protected override void PerformAction(object parameter)
        {
            var photo = parameter as FacebookPhoto;

            if (photo == null)
            {
                return;
            }

            string defaultFileName = "Facebook Photo";

            if (photo.Album != null)
            {
                defaultFileName = photo.Album.Title + " (" + (photo.Album.Photos.IndexOf(photo) + 1) + ")";
            }

            string filePath = null;

            if (Utility.IsOSVistaOrNewer)
            {
                IFileSaveDialog pFileSaveDialog = null;
                try
                {
                    pFileSaveDialog = CLSID.CoCreateInstance <IFileSaveDialog>(CLSID.FileSaveDialog);
                    pFileSaveDialog.SetOptions(pFileSaveDialog.GetOptions() | FOS.FORCEFILESYSTEM | FOS.OVERWRITEPROMPT);
                    pFileSaveDialog.SetTitle("Select where to save the photo");
                    pFileSaveDialog.SetOkButtonLabel("Save Photo");
                    var filterspec = new COMDLG_FILTERSPEC {
                        pszName = "Images", pszSpec = "*.jpg;*.png;*.bmp;*.gif"
                    };
                    pFileSaveDialog.SetFileTypes(1, ref filterspec);
                    pFileSaveDialog.SetFileName(defaultFileName);
                    Guid clientId = _SavePhotoId;
                    pFileSaveDialog.SetClientGuid(ref clientId);

                    IShellItem pItem = null;
                    try
                    {
                        pItem = ShellUtil.GetShellItemForPath(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures));
                        pFileSaveDialog.SetDefaultFolder(pItem);
                    }
                    finally
                    {
                        Utility.SafeRelease(ref pItem);
                    }

                    HRESULT hr = pFileSaveDialog.Show(new WindowInteropHelper(Application.Current.MainWindow).Handle);
                    if (hr.Failed)
                    {
                        Assert.AreEqual((HRESULT)Win32Error.ERROR_CANCELLED, hr);
                        return;
                    }

                    pItem = null;
                    try
                    {
                        pItem    = pFileSaveDialog.GetResult();
                        filePath = ShellUtil.GetPathFromShellItem(pItem);
                    }
                    finally
                    {
                        Utility.SafeRelease(ref pItem);
                    }
                }
                finally
                {
                    Utility.SafeRelease(ref pFileSaveDialog);
                }
            }
            else
            {
                var saveFileDialog = new Microsoft.Win32.SaveFileDialog
                {
                    Filter           = "Image Files|*.jpg;*.png;*.bmp;*.gif",
                    FileName         = defaultFileName,
                    InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures),
                };

                if (saveFileDialog.ShowDialog(Application.Current.MainWindow) != true)
                {
                    return;
                }

                filePath = saveFileDialog.FileName;
            }

            FacebookImageSaveOptions fiso = FacebookImageSaveOptions.FindBetterName;

            // We told the file dialog to prompt about overwriting, so if the user specified a location
            // with a file extension and the file already exists, prepare to overwrite.
            // This isn't quite right because the file extension may be different, so we may overwrite a jpg
            // when it was asked to be a gif, but it's not a likely scenario.
            if (System.IO.File.Exists(filePath))
            {
                fiso = FacebookImageSaveOptions.Overwrite;
            }

            photo.Image.SaveToFile(FacebookImageDimensions.Big, filePath, true, fiso, _OnPhotoSaveProgressCallback, null);
        }
コード例 #31
0
        public void Write(System.IO.BinaryWriter bw)
        {
            var oc0 = new OffsetContainer();
            var oc1 = new OffsetContainer();

            bw.Write(ByteOrder);
            bw.Write(Version);
            bw.Write(SystemIdentifier);
            bw.Write(CLSID.ToByteArray());
            bw.Write(NumPropertySets);
            bw.Write(FMTID0.ToByteArray());
            bw.Write(Offset0);

            if (NumPropertySets == 2)
            {
                bw.Write(FMTID1.ToByteArray());
                bw.Write(Offset1);
            }


            oc0.OffsetPS = (int)bw.BaseStream.Position;
            bw.Write(PropertySet0.Size);
            bw.Write(PropertySet0.NumProperties);

            // w property offsets
            for (int i = 0; i < PropertySet0.NumProperties; i++)
            {
                oc0.PropertyIdentifierOffsets.Add(bw.BaseStream.Position); //Offset of 4 to Offset value
                PropertySet0.PropertyIdentifierAndOffsets[i].Write(bw);
            }

            for (int i = 0; i < PropertySet0.NumProperties; i++)
            {
                oc0.PropertyOffsets.Add(bw.BaseStream.Position);
                PropertySet0.Properties[i].Write(bw);
            }

            var padding0 = bw.BaseStream.Position % 4;

            //if (padding0 > 0)
            //{
            //    for (int p = 0; p < padding0; p++)
            //        bw.Write((byte)0);
            //}

            int size0 = (int)(bw.BaseStream.Position - oc0.OffsetPS);



            if (NumPropertySets == 2)
            {
                oc1.OffsetPS = (int)bw.BaseStream.Position;

                bw.Write(PropertySet1.Size);
                bw.Write(PropertySet1.NumProperties);

                // w property offsets
                for (int i = 0; i < PropertySet1.PropertyIdentifierAndOffsets.Count; i++)
                {
                    oc1.PropertyIdentifierOffsets.Add(bw.BaseStream.Position); //Offset of 4 to Offset value
                    PropertySet1.PropertyIdentifierAndOffsets[i].Write(bw);
                }

                for (int i = 0; i < PropertySet1.NumProperties; i++)
                {
                    oc1.PropertyOffsets.Add(bw.BaseStream.Position);
                    PropertySet1.Properties[i].Write(bw);
                }

                int size1 = (int)(bw.BaseStream.Position - oc1.OffsetPS);

                bw.Seek(oc1.OffsetPS + 4, System.IO.SeekOrigin.Begin);
                bw.Write(size1);
            }

            bw.Seek(oc0.OffsetPS, System.IO.SeekOrigin.Begin);
            bw.Write(size0);

            int shiftO1 = 2 + 2 + 4 + 16 + 4 + 16; //OFFSET0

            bw.Seek(shiftO1, System.IO.SeekOrigin.Begin);
            bw.Write(oc0.OffsetPS);

            if (NumPropertySets == 2)
            {
                bw.Seek(shiftO1 + 4 + 16, System.IO.SeekOrigin.Begin);
                bw.Write(oc1.OffsetPS);
            }

            //-----------

            for (int i = 0; i < PropertySet0.PropertyIdentifierAndOffsets.Count; i++)
            {
                bw.Seek((int)oc0.PropertyIdentifierOffsets[i] + 4, System.IO.SeekOrigin.Begin); //Offset of 4 to Offset value
                bw.Write((int)(oc0.PropertyOffsets[i] - oc0.OffsetPS));
            }



            if (PropertySet1 != null)
            {
                for (int i = 0; i < PropertySet1.PropertyIdentifierAndOffsets.Count; i++)
                {
                    bw.Seek((int)oc1.PropertyIdentifierOffsets[i], System.IO.SeekOrigin.Begin); //Offset of 4 to Offset value
                    bw.Write(oc1.PropertyOffsets[i] - oc1.OffsetPS);
                }
            }
        }
コード例 #32
0
ファイル: XlAddIn.cs プロジェクト: Ryknyk/ExcelDna
 internal static HRESULT DllGetClassObject(CLSID clsid, IID iid, out IntPtr ppunk)
 {
     Debug.Print("DllGetClassObject entered - calling InitializeIntegration.");
     HRESULT result;
     InitializeIntegration();
     Logger.Initialization.Verbose("In DllGetClassObject");
     result = IntegrationHelpers.DllGetClassObject(clsid, iid, out ppunk);
     return result;
 }
コード例 #33
0
ファイル: XlAddIn.cs プロジェクト: ravikp/rims.net
 internal static HRESULT DllGetClassObject(CLSID clsid, IID iid, out IntPtr ppunk)
 {
     Debug.Print("DllGetClassObject reached!!");
    // IntPtr pout;
     HRESULT result;
     InitializeIntegration();
     result = IntegrationHelpers.DllGetClassObject(clsid, iid, out ppunk);
     return result;
 }
コード例 #34
0
ファイル: ComServer.cs プロジェクト: gjvdkamp/ExcelDna
 internal static void RegisterClassFactory(CLSID clsId, ComAPI.IClassFactory classFactory)
 {
     // CONSIDER: Do we need to deal with the case where it is already in the list?
     //           For now we expect it to throw...
     registeredClassFactories.Add(clsId, classFactory);
 }