Esempio n. 1
0
        public static _RemotableHandle HWNDtoRemotableHandle(IntPtr hwnd)
        {
            _RemotableHandle handle = new _RemotableHandle();

            Kernel32.CopyMemory(ref handle, ref hwnd, IntPtr.Size);
            return(handle);
        }
Esempio n. 2
0
        private static Win32 LnkProgram(string path)
        {
            var program = Win32Program(path);

            try
            {
                var        link      = new ShellLink();
                const uint STGM_READ = 0;
                ((IPersistFile)link).Load(path, STGM_READ);
                var hwnd = new _RemotableHandle();
                link.Resolve(ref hwnd, 0);

                const int     MAX_DESCRIPTION   = 150;
                StringBuilder bufferDescription = new StringBuilder(MAX_DESCRIPTION);
                String        description       = String.Empty;
                try
                {
                    link.GetDescription(bufferDescription, MAX_DESCRIPTION);
                }
                catch (COMException e)
                {
                    Log.Error($"|Win32.LnkProgram|cannot get description <{path}>. HResult: <{e.HResult}>. Exception: <{e}>.");
                    bufferDescription.Clear();
                }
                description = bufferDescription.ToString();
                if (!string.IsNullOrEmpty(description))
                {
                    program.Description = description;
                }
                else
                {
                    const int     MAX_PATH       = 260;
                    StringBuilder bufferPath     = new StringBuilder(MAX_PATH);
                    var           data           = new _WIN32_FIND_DATAW();
                    const uint    SLGP_SHORTPATH = 1;
                    link.GetPath(bufferPath, bufferPath.Capacity, ref data, SLGP_SHORTPATH);
                    var target = bufferPath.ToString();
                    if (!string.IsNullOrEmpty(target))
                    {
                        var extension = Extension(target);
                        if (extension == ExeExtension && File.Exists(target))
                        {
                            var info = FileVersionInfo.GetVersionInfo(target);
                            if (!string.IsNullOrEmpty(info.FileDescription))
                            {
                                program.Description = info.FileDescription;
                            }
                        }
                    }
                }
                return(program);
            }

            catch (Exception e)
            {
                Log.Exception($"|Win32.LnkProgram|Exception when parsing shortcut <{path}>", e);
                program.Valid = false;
                return(program);
            }
        }
        // Retrieve the target path using Shell Link
        public string retrieveTargetPath(string path)
        {
            var       link      = new ShellLink();
            const int STGM_READ = 0;

            ((IPersistFile)link).Load(path, STGM_READ);
            var hwnd = new _RemotableHandle();

            ((IShellLinkW)link).Resolve(ref hwnd, 0);

            const int     MAX_PATH = 260;
            StringBuilder buffer   = new StringBuilder(MAX_PATH);

            var data = new WIN32_FIND_DATAW();

            ((IShellLinkW)link).GetPath(buffer, buffer.Capacity, ref data, SLGP_FLAGS.SLGP_SHORTPATH);
            var target = buffer.ToString();

            // To set the app description
            if (!String.IsNullOrEmpty(target))
            {
                buffer = new StringBuilder(MAX_PATH);
                ((IShellLinkW)link).GetDescription(buffer, MAX_PATH);
                description = buffer.ToString();
            }

            // To release unmanaged memory
            Marshal.ReleaseComObject(link);

            return(target);
        }
Esempio n. 4
0
        private static Win32 LnkProgram(string path)
        {
            var program = Win32Program(path);

            try
            {
                var        link      = new ShellLink();
                const uint STGM_READ = 0;
                ((IPersistFile)link).Load(path, STGM_READ);
                var hwnd = new _RemotableHandle();
                link.Resolve(ref hwnd, 0);

                const int     MAX_PATH = 260;
                StringBuilder buffer   = new StringBuilder(MAX_PATH);

                var        data           = new _WIN32_FIND_DATAW();
                const uint SLGP_SHORTPATH = 1;
                link.GetPath(buffer, buffer.Capacity, ref data, SLGP_SHORTPATH);
                var target = buffer.ToString();
                if (!string.IsNullOrEmpty(target))
                {
                    var extension = Extension(target);
                    if (extension == ExeExtension && File.Exists(target))
                    {
                        buffer = new StringBuilder(MAX_PATH);
                        link.GetDescription(buffer, MAX_PATH);
                        var description = buffer.ToString();
                        if (!string.IsNullOrEmpty(description))
                        {
                            program.Description = description;
                        }
                        else
                        {
                            var info = FileVersionInfo.GetVersionInfo(target);
                            if (!string.IsNullOrEmpty(info.FileDescription))
                            {
                                program.Description = info.FileDescription;
                            }
                        }
                    }
                }
                return(program);
            }
            catch (COMException e)
            {
                // C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\MiracastView.lnk always cause exception
                Log.Error($"COMException when parsing shortcut: {path}, HResult: {e.HResult}");
                Log.Exception(e);
                program.Valid = false;
                return(program);
            }
            catch (Exception e)
            {
                Log.Error($"Error when parsing shortcut: {path}");
                Log.Exception(e);
                program.Valid = false;
                return(program);
            }
        }
Esempio n. 5
0
        // Retrieve the target path using Shell Link
        public string RetrieveTargetPath(string path)
        {
            var       link      = new ShellLink();
            const int STGM_READ = 0;

            try
            {
                ((IPersistFile)link).Load(path, STGM_READ);
            }
            catch (System.IO.FileNotFoundException ex)
            {
                ProgramLogger.LogException($"|Win32| ShellLinkHelper.retrieveTargetPath | {path} | Path could not be retrieved", ex);
                return(String.Empty);
            }

            var hwnd = new _RemotableHandle();

            ((IShellLinkW)link).Resolve(ref hwnd, 0);

            const int     MAX_PATH = 260;
            StringBuilder buffer   = new StringBuilder(MAX_PATH);

            var data = new WIN32_FIND_DATAW();

            ((IShellLinkW)link).GetPath(buffer, buffer.Capacity, ref data, SLGP_FLAGS.SLGP_SHORTPATH);
            var target = buffer.ToString();

            // To set the app description
            if (!String.IsNullOrEmpty(target))
            {
                buffer = new StringBuilder(MAX_PATH);
                ((IShellLinkW)link).GetDescription(buffer, MAX_PATH);
                description = buffer.ToString();

                StringBuilder argumentBuffer = new StringBuilder(MAX_PATH);
                ((IShellLinkW)link).GetArguments(argumentBuffer, argumentBuffer.Capacity);
                Arguments = argumentBuffer.ToString();

                // Set variable to true if the program takes in any arguments
                if (argumentBuffer.Length != 0)
                {
                    hasArguments = true;
                }
            }
            return(target);
        }
Esempio n. 6
0
        private static Win32 LnkProgram(string path)
        {
            var program = Win32Program(path);

            try
            {
                var        link      = new ShellLink();
                const uint STGM_READ = 0;
                ((IPersistFile)link).Load(path, STGM_READ);
                var hwnd = new _RemotableHandle();
                link.Resolve(ref hwnd, 0);

                const int     MAX_PATH = 260;
                StringBuilder buffer   = new StringBuilder(MAX_PATH);

                var        data           = new _WIN32_FIND_DATAW();
                const uint SLGP_SHORTPATH = 1;
                link.GetPath(buffer, buffer.Capacity, ref data, SLGP_SHORTPATH);
                var target    = buffer.ToString();
                var extension = Extension(target);
                if (!string.IsNullOrEmpty(target) && (extension == ExeExtension))
                {
                    buffer = new StringBuilder(MAX_PATH);
                    link.GetDescription(buffer, MAX_PATH);
                    var description = buffer.ToString();
                    if (!string.IsNullOrEmpty(description))
                    {
                        program.Description = description;
                    }
                    else
                    {
                        var info = FileVersionInfo.GetVersionInfo(target);
                        if (!string.IsNullOrEmpty(info.FileDescription))
                        {
                            program.Description = info.FileDescription;
                        }
                    }
                }
                return(program);
            }
            catch (Exception)
            {
                Log.Error($"Error when parsing shortcut: {path}");
                return(program);
            }
        }
        // Retrieve the target path using Shell Link
        public string retrieveTargetPath(string path)
        {
            var       link      = new ShellLink();
            const int STGM_READ = 0;

            ((IPersistFile)link).Load(path, STGM_READ);
            var hwnd = new _RemotableHandle();

            ((IShellLinkW)link).Resolve(ref hwnd, 0);

            const int     MAX_PATH = 260;
            StringBuilder buffer   = new StringBuilder(MAX_PATH);

            var data = new WIN32_FIND_DATAW();

            ((IShellLinkW)link).GetPath(buffer, buffer.Capacity, ref data, SLGP_FLAGS.SLGP_SHORTPATH);
            var target = buffer.ToString();

            // To set the app description
            if (!String.IsNullOrEmpty(target))
            {
                buffer = new StringBuilder(MAX_PATH);
                ((IShellLinkW)link).GetDescription(buffer, MAX_PATH);
                description = buffer.ToString();

                StringBuilder argumentBuffer = new StringBuilder(MAX_PATH);
                ((IShellLinkW)link).GetArguments(argumentBuffer, argumentBuffer.Capacity);
                Arguments = argumentBuffer.ToString();

                // Set variable to true if the program takes in any arguments
                if (argumentBuffer.Length != 0)
                {
                    hasArguments = true;
                }
            }
            return(target);
        }
 public virtual void ClearHmenuProps(_RemotableHandle& hmenu, uint idChild, System.Guid& paProps, int cProps)
 {
 }
 public virtual void SetHmenuPropStr(_RemotableHandle& hmenu, uint idChild, System.Guid idProp, string str)
 {
 }
Esempio n. 10
0
 public virtual Int32 Draw(tagRECT rcBounds, tagRECT rcUpdate, Int32 lDrawFlags, _RemotableHandle hdc, object pvDrawObject)
 {
     return(InvokerService.InvokeInternal.ExecuteInt32MethodGet(this, "Draw", new object[] { rcBounds, rcUpdate, lDrawFlags, hdc, pvDrawObject }));
 }
Esempio n. 11
0
        private static Win32 LnkProgram(string path)
        {
            var program = Win32Program(path);

            try
            {
                var        link      = new ShellLink();
                const uint STGM_READ = 0;
                ((IPersistFile)link).Load(path, STGM_READ);
                var hwnd = new _RemotableHandle();
                link.Resolve(ref hwnd, 0);

                const int     MAX_PATH = 260;
                StringBuilder buffer   = new StringBuilder(MAX_PATH);

                var        data           = new _WIN32_FIND_DATAW();
                const uint SLGP_SHORTPATH = 1;
                link.GetPath(buffer, buffer.Capacity, ref data, SLGP_SHORTPATH);
                var target = buffer.ToString();
                if (!string.IsNullOrEmpty(target))
                {
                    var extension = Extension(target);
                    if (extension == ExeExtension && File.Exists(target))
                    {
                        program.LnkResolvedPath = program.FullPath;
                        program.FullPath        = Path.GetFullPath(target).ToLower();
                        program.ExecutableName  = Path.GetFileName(target);

                        buffer = new StringBuilder(MAX_PATH);
                        link.GetDescription(buffer, MAX_PATH);
                        var description = buffer.ToString();
                        if (!string.IsNullOrEmpty(description))
                        {
                            program.Description = description;
                        }
                        else
                        {
                            var info = FileVersionInfo.GetVersionInfo(target);
                            if (!string.IsNullOrEmpty(info.FileDescription))
                            {
                                program.Description = info.FileDescription;
                            }
                        }
                    }
                }
                return(program);
            }
            catch (COMException e)
            {
                // C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\MiracastView.lnk always cause exception
                ProgramLogger.LogException($"|Win32|LnkProgram|{path}" +
                                           "|Error caused likely due to trying to get the description of the program", e);

                program.Valid = false;
                return(program);
            }
#if !DEBUG //Only do a catch all in production. This is so make developer aware of any unhandled exception and add the exception handling in.
            catch (Exception e)
            {
                ProgramLogger.LogException($"|Win32|LnkProgram|{path}" +
                                           "|An unexpected error occurred in the calling method LnkProgram", e);

                program.Valid = false;
                return(program);
            }
#endif
        }
Esempio n. 12
0
 public void paintCustomScrollbar(WebView WebView, ref _RemotableHandle hDC, tagRECT rect, WebScrollBarControlSize size, uint state, WebScrollbarControlPart pressedPart, int vertical, float value, float proportion, uint parts)
 {
 }
	public virtual void ComposeHmenuIdentityString(_RemotableHandle& hmenu, uint idChildout , System.IntPtr ppIDStringout , System.UInt32& pdwIDStringLen) {}
 public void set_ParentHwnd(ref _RemotableHandle retval)
 {
     throw new NotImplementedException();
 }
Esempio n. 15
0
 public virtual Int32 InvalidateRegion(_RemotableHandle rgnInvalid)
 {
     return(InvokerService.InvokeInternal.ExecuteInt32MethodGet(this, "InvalidateRegion", rgnInvalid));
 }
Esempio n. 16
0
 public void AddLiveWindow(int in_nType, ref _RemotableHandle in_hParent, tagRECT in_rcRect)
 {
     _bsEditApplication.AddLiveWindow(in_nType, ref in_hParent, in_rcRect);
 }
Esempio n. 17
0
 public virtual Int32 DrawToDC(_RemotableHandle hdc)
 {
     return(InvokerService.InvokeInternal.ExecuteInt32MethodGet(this, "DrawToDC", hdc));
 }
Esempio n. 18
0
 public virtual Int32 SetDocumentPrinter(string bstrPrinterName, _RemotableHandle hdc)
 {
     return(InvokerService.InvokeInternal.ExecuteInt32MethodGet(this, "SetDocumentPrinter", bstrPrinterName, hdc));
 }
Esempio n. 19
0
        private static Win32 LnkProgram(string path)
        {
            var program = Win32Program(path);
            try
            {
                var link = new ShellLink();
                const uint STGM_READ = 0;
                ((IPersistFile)link).Load(path, STGM_READ);
                var hwnd = new _RemotableHandle();
                link.Resolve(ref hwnd, 0);

                const int MAX_PATH = 260;
                StringBuilder buffer = new StringBuilder(MAX_PATH);

                var data = new _WIN32_FIND_DATAW();
                const uint SLGP_SHORTPATH = 1;
                link.GetPath(buffer, buffer.Capacity, ref data, SLGP_SHORTPATH);
                var target = buffer.ToString();
                var extension = Extension(target);
                if (!string.IsNullOrEmpty(target) && (extension == ExeExtension))
                {
                    buffer = new StringBuilder(MAX_PATH);
                    link.GetDescription(buffer, MAX_PATH);
                    var description = buffer.ToString();
                    if (!string.IsNullOrEmpty(description))
                    {
                        program.Description = description;
                    }
                    else
                    {
                        var info = FileVersionInfo.GetVersionInfo(target);
                        if (!string.IsNullOrEmpty(info.FileDescription))
                        {
                            program.Description = info.FileDescription;
                        }
                    }
                }
                return program;
            }
            catch (Exception)
            {
                Log.Error($"Error when parsing shortcut: {path}");
                return program;
            }
        }
	public virtual void SetHmenuPropServer(_RemotableHandle& hmenu, uint idChild, System.Guid& paProps, int cProps, IAccPropServer pServer, AnnoScope AnnoScope) {}
Esempio n. 21
0
 public void paintCustomScrollbar(WebView WebView, ref _RemotableHandle hDC, tagRECT rect, WebScrollBarControlSize size, uint state, WebScrollbarControlPart pressedPart, int vertical, float value, float proportion, uint parts)
 {
 }
	public virtual void ClearHmenuProps(_RemotableHandle& hmenu, uint idChild, System.Guid& paProps, int cProps) {}
 public virtual void SetHwndProp(_RemotableHandle& hwnd, uint idObject, uint idChild, System.Guid idProp, object var)
 {
 }
Esempio n. 24
0
 public void paintCustomScrollCorner(WebView WebView, ref _RemotableHandle hDC, tagRECT rect)
 {
 }
 public virtual void SetHwndPropServer(_RemotableHandle& hwnd, uint idObject, uint idChild, System.Guid& paProps, int cProps, IAccPropServer pServer, AnnoScope AnnoScope)
 {
 }
Esempio n. 26
0
        private static Win32 LnkProgram(string path)
        {
            var program = Win32Program(path);
            try
            {
                var link = new ShellLink();
                const uint STGM_READ = 0;
                ((IPersistFile) link).Load(path, STGM_READ);
                var hwnd = new _RemotableHandle();
                link.Resolve(ref hwnd, 0);

                const int MAX_PATH = 260;
                StringBuilder buffer = new StringBuilder(MAX_PATH);

                var data = new _WIN32_FIND_DATAW();
                const uint SLGP_SHORTPATH = 1;
                link.GetPath(buffer, buffer.Capacity, ref data, SLGP_SHORTPATH);
                var target = buffer.ToString();
                if (!string.IsNullOrEmpty(target))
                {
                    var extension = Extension(target);
                    if (extension == ExeExtension && File.Exists(target))
                    {
                        buffer = new StringBuilder(MAX_PATH);
                        link.GetDescription(buffer, MAX_PATH);
                        var description = buffer.ToString();
                        if (!string.IsNullOrEmpty(description))
                        {
                            program.Description = description;
                        }
                        else
                        {
                            var info = FileVersionInfo.GetVersionInfo(target);
                            if (!string.IsNullOrEmpty(info.FileDescription))
                            {
                                program.Description = info.FileDescription;
                            }
                        }
                    }
                }
                return program;
            }
            catch (COMException e)
            {
                // C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\MiracastView.lnk always cause exception
                Log.Error($"COMException when parsing shortcut: {path}, HResult: {e.HResult}");
                Log.Exception(e);
                program.Valid = false;
                return program;
            }
            catch (Exception e)
            {
                Log.Error($"Error when parsing shortcut: {path}");
                Log.Exception(e);
                program.Valid = false;
                return program;
            }
        }
 public virtual void ComposeHwndIdentityString(_RemotableHandle& hwnd, uint idObject, uint idChildout, System.IntPtr ppIDStringout, System.UInt32& pdwIDStringLen)
 {
 }
	public virtual void SetHwndProp(_RemotableHandle& hwnd, uint idObject, uint idChild, System.Guid idProp, object var) {}
Esempio n. 29
0
 public virtual Int32 Draw(_RemotableHandle hdc, Int32 lLayer, tagRECT pRect, object pReserved)
 {
     return(InvokerService.InvokeInternal.ExecuteInt32MethodGet(this, "Draw", hdc, lLayer, pRect, pReserved));
 }
Esempio n. 30
0
 public void paintCustomScrollCorner(WebView WebView, ref _RemotableHandle hDC, tagRECT rect)
 {
 }
	public virtual void SetHwndPropStr(_RemotableHandle& hwnd, uint idObject, uint idChild, System.Guid idProp, string str) {}
 public virtual void SetHwndPropStr(_RemotableHandle& hwnd, uint idObject, uint idChild, System.Guid idProp, string str)
 {
 }
	public virtual void SetHwndPropServer(_RemotableHandle& hwnd, uint idObject, uint idChild, System.Guid& paProps, int cProps, IAccPropServer pServer, AnnoScope AnnoScope) {}
 public virtual void ClearHwndProps(_RemotableHandle& hwnd, uint idObject, uint idChild, System.Guid& paProps, int cProps)
 {
 }
	public virtual void ClearHwndProps(_RemotableHandle& hwnd, uint idObject, uint idChild, System.Guid& paProps, int cProps) {}
 public virtual void SetHmenuProp(_RemotableHandle& hmenu, uint idChild, System.Guid idProp, object var)
 {
 }
	public virtual void ComposeHwndIdentityString(_RemotableHandle& hwnd, uint idObject, uint idChildout , System.IntPtr ppIDStringout , System.UInt32& pdwIDStringLen) {}
 public virtual void SetHmenuPropServer(_RemotableHandle& hmenu, uint idChild, System.Guid& paProps, int cProps, IAccPropServer pServer, AnnoScope AnnoScope)
 {
 }
	public virtual void SetHmenuProp(_RemotableHandle& hmenu, uint idChild, System.Guid idProp, object var) {}
 public virtual void ComposeHmenuIdentityString(_RemotableHandle& hmenu, uint idChildout, System.IntPtr ppIDStringout, System.UInt32& pdwIDStringLen)
 {
 }
	public virtual void SetHmenuPropStr(_RemotableHandle& hmenu, uint idChild, System.Guid idProp, string str) {}