Example #1
0
        private static NtResult <string[]> GetAppIds(string full_name)
        {
            var result = Win32NativeMethods.OpenPackageInfoByFullName(full_name, 0, out IntPtr package_info);

            if (result != Win32Error.SUCCESS)
            {
                return(result.CreateResultFromDosError <string[]>(false));
            }
            try {
                int length = 0;
                result = Win32NativeMethods.GetPackageApplicationIds(package_info, ref length, SafeHGlobalBuffer.Null, out int count);
                if (result != Win32Error.ERROR_INSUFFICIENT_BUFFER)
                {
                    return(result.CreateResultFromDosError <string[]>(false));
                }
                using (var buffer = new SafeHGlobalBuffer(length)) {
                    return(Win32NativeMethods.GetPackageApplicationIds(package_info, ref length, buffer, out count)
                           .CreateWin32Result(false, () => ReadStrings(buffer, count)));
                }
            } finally {
                if (package_info != IntPtr.Zero)
                {
                    Win32NativeMethods.ClosePackageInfo(package_info);
                }
            }
        }