Esempio n. 1
0
        public static string QueryAssociationString(string assoc, AssociationString str, AssociationFlags flags, string extra = null)
        {
            if (assoc == null)
            {
                throw new ArgumentNullException("assoc");
            }

            flags |= AssociationFlags.NoTruncate;

            const uint E_POINTER        = 0x80004003;
            const uint E_NO_ASSOCIATION = 0x80070483;

            var builder = new StringBuilder(512);
            int size    = builder.Length;

            var result = Win32.AssocQueryStringW(flags, str, assoc, extra, builder, ref size);

            if (result == unchecked ((int)E_POINTER))
            {
                builder.Length = size;
                result         = Win32.AssocQueryStringW(flags, str, assoc, extra, builder, ref size);
            }

            if (result == unchecked ((int)E_NO_ASSOCIATION))
            {
                return(null);
            }

            Marshal.ThrowExceptionForHR(result);
            return(builder.ToString());
        }
 public static extern HResult AssocQueryStringByKeyW(
     AssociationFlags flags,
     AssociationString str,
     RegistryKeyHandle hkAssoc,
     string pszExtra,
     SafeHandle pszOut,
     ref uint pcchOut);
Esempio n. 3
0
        public static string AssocQueryString(AssociationFlags flags, AssociationString @string, string association, string extraInfo)
        {
            return(BufferHelper.BufferInvoke((StringBuffer buffer) =>
            {
                flags |= AssociationFlags.NoTruncate;

                HResult result;
                uint count = buffer.CharCapacity;
                while ((result = Imports.AssocQueryStringW(flags, @string, association, extraInfo, buffer, ref count)) == HResult.E_POINTER)
                {
                    buffer.EnsureCharCapacity(count);
                }

                result.ThrowIfFailed(association);

                // Count includes the null
                buffer.Length = count - 1;
                return buffer.ToString();
            }));
        }
Esempio n. 4
0
        private static string GetFileAssociationCore(string path, AssociationAttributes attributes, AssociationString associationType)
        {
            if (Utils.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException("path");
            }

            attributes = attributes | AssociationAttributes.NoTruncate | AssociationAttributes.RemapRunDll;

            uint          bufferSize = NativeMethods.MaxPath;
            StringBuilder buffer;
            uint          retVal;

            do
            {
                buffer = new StringBuilder((int)bufferSize);

                // AssocQueryString()
                // In the ANSI version of this function, the name is limited to 248 characters.
                // To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
                // 2014-02-05: MSDN does not confirm LongPath usage but a Unicode version of this function exists.
                // However, the function fails when using Unicode format.

                retVal = NativeMethods.AssocQueryString(attributes, associationType, path, null, buffer, out bufferSize);

                // No Exception is thrown, just return empty string on error.

                //switch (retVal)
                //{
                //   // 0x80070483: No application is associated with the specified file for this operation.
                //   case 2147943555:
                //   case Win32Errors.E_POINTER:
                //   case Win32Errors.S_OK:
                //      break;

                //   default:
                //      NativeError.ThrowException(retVal);
                //      break;
                //}
            } while (retVal == Win32Errors.E_POINTER);

            return(buffer.ToString());
        }
		public static string QueryAssociationString (string assoc, AssociationString str, AssociationFlags flags, string extra = null)
		{
			if (assoc == null)
				throw new ArgumentNullException("assoc");

			flags |= AssociationFlags.NoTruncate;

			const uint E_POINTER = 0x80004003;
			const uint E_NO_ASSOCIATION = 0x80070483;

			var builder = new StringBuilder (512);
			int size = builder.Length;

			var result = Win32.AssocQueryStringW (flags, str, assoc, extra, builder, ref size);

			if (result == unchecked((int)E_POINTER)) {
				builder.Length = size;
				result = Win32.AssocQueryStringW (flags, str, assoc, extra, builder, ref size);
			}

			if (result == unchecked((int)E_NO_ASSOCIATION)) {
				return null;
			}

			Marshal.ThrowExceptionForHR (result);
			return builder.ToString ();
		}
Esempio n. 6
0
	 public static extern int AssocQueryStringW (AssociationFlags flags, AssociationString str, string assoc, string extra, StringBuilder outBuffer, ref int outBufferSize);
Esempio n. 7
0
 public static extern int AssocQueryStringW(AssociationFlags flags, AssociationString str, string assoc, string extra, StringBuilder outBuffer, ref int outBufferSize);
Esempio n. 8
0
      private static string GetFileAssociationInternal(string path, AssociationAttributes attributes, AssociationString associationType)
      {
         if (Utils.IsNullOrWhiteSpace(path))
            throw new ArgumentNullException("path");

         attributes = attributes | AssociationAttributes.NoTruncate | AssociationAttributes.RemapRunDll;

         uint bufferSize = NativeMethods.MaxPath;
         StringBuilder buffer;
         uint retVal;

         do
         {
            buffer = new StringBuilder((int)bufferSize);

            // AssocQueryString()
            // In the ANSI version of this function, the name is limited to 248 characters.
            // To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
            // 2014-02-05: MSDN does not confirm LongPath usage but a Unicode version of this function exists.
            // However, the function fails when using Unicode format.

            retVal = NativeMethods.AssocQueryString(attributes, associationType, path, null, buffer, out bufferSize);

            // No Exception is thrown, just return empty string on error.

            //switch (retVal)
            //{
            //   // 0x80070483: No application is associated with the specified file for this operation.
            //   case 2147943555:
            //   case Win32Errors.E_POINTER:
            //   case Win32Errors.S_OK:
            //      break;

            //   default:
            //      NativeError.ThrowException(retVal);
            //      break;
            //}

         } while (retVal == Win32Errors.E_POINTER);

         return buffer.ToString();
      }
Esempio n. 9
0
        private static string GetFileAssociationCore(string path, AssociationAttributes attributes, AssociationString associationType)
        {
            if (Utils.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException("path");
            }

            attributes = attributes | AssociationAttributes.NoTruncate | AssociationAttributes.RemapRunDll;

            uint          bufferSize = NativeMethods.MaxPath;
            StringBuilder buffer;
            uint          retVal;

            do
            {
                buffer = new StringBuilder((int)bufferSize);

                // AssocQueryString()
                // 2014-02-05: MSDN does not confirm LongPath usage but a Unicode version of this function exists.
                // 2015-07-17: This function does not support long paths.

                retVal = NativeMethods.AssocQueryString(attributes, associationType, path, null, buffer, out bufferSize);

                // No Exception is thrown, just return empty string on error.

                //switch (retVal)
                //{
                //   // 0x80070483: No application is associated with the specified file for this operation.
                //   case 2147943555:
                //   case Win32Errors.E_POINTER:
                //   case Win32Errors.S_OK:
                //      break;

                //   default:
                //      NativeError.ThrowException(retVal);
                //      break;
                //}
            } while (retVal == Win32Errors.E_POINTER);

            return(buffer.ToString());
        }