Exemplo n.º 1
0
            private static string GetCommandString(Shell32.IContextMenu cMenu, uint offset, Shell32.GCS flags = Shell32.GCS.GCS_VERBW)
            {
                if (offset > 5000)
                {
                    // Hackish workaround to avoid an AccessViolationException on some items,
                    // notably the "Run with graphic processor" menu item of NVidia cards
                    return(null);
                }
                SafeCoTaskMemString commandString = null;

                try
                {
                    commandString = new SafeCoTaskMemString(512);
                    cMenu.GetCommandString(new IntPtr(offset), flags, IntPtr.Zero, commandString, (uint)commandString.Capacity - 1);
                    Debug.WriteLine("Verb {0}: {1}", offset, commandString);
                    return(commandString.ToString());
                }
                catch (Exception ex) when(ex is InvalidCastException || ex is ArgumentException)
                {
                    // TODO: investigate this..
                    Debug.WriteLine(ex);
                    return(null);
                }
                catch (Exception ex) when(ex is COMException || ex is NotImplementedException)
                {
                    // Not every item has an associated verb
                    return(null);
                }
                finally
                {
                    commandString?.Dispose();
                }
            }
Exemplo n.º 2
0
            private static string GetCommandString(Shell32.IContextMenu cMenu, uint offset, Shell32.GCS flags = Shell32.GCS.GCS_VERBW)
            {
                SafeCoTaskMemString commandString = null;

                try
                {
                    commandString = new SafeCoTaskMemString(512);
                    cMenu.GetCommandString(new IntPtr(offset), flags, IntPtr.Zero, commandString, (uint)commandString.Capacity - 1);
                    Debug.WriteLine("Verb {0}: {1}", offset, commandString);
                    return(commandString.ToString());
                }
                catch (Exception ex) when(ex is InvalidCastException || ex is ArgumentException)
                {
                    // TODO: investigate this..
                    Debug.WriteLine(ex);
                    return(null);
                }
                catch (Exception ex) when(ex is COMException || ex is NotImplementedException)
                {
                    // Not every item has an associated verb
                    return(null);
                }
                finally
                {
                    commandString?.Dispose();
                }
            }