Example #1
0
        public static IReadOnlyList <ColorProfile> GetColorProfiles(string machineName = null)
        {
            var list     = new List <ColorProfile>();
            var size     = 0;
            var enumType = new ENUMTYPE();

            enumType.dwSize    = Marshal.SizeOf(enumType);
            enumType.dwVersion = ENUM_TYPE_VERSION;
            if (!EnumColorProfiles(machineName, ref enumType, IntPtr.Zero, ref size, out var count))
            {
                var gle = Marshal.GetLastWin32Error();
                if (gle != ERROR_INSUFFICIENT_BUFFER)
                {
                    throw new Win32Exception(gle);
                }
            }

            if (count > 0)
            {
                using (var mem = new ComMemory(size))
                {
                    if (!EnumColorProfiles(machineName, ref enumType, mem.Pointer, ref size, out count))
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    }

                    var ptr = mem.Pointer;
                    do
                    {
                        var str = Marshal.PtrToStringUni(ptr);
                        if (string.IsNullOrEmpty(str))
                        {
                            break;
                        }

                        try
                        {
                            var profile = FromFileName(str, machineName);
                            if (profile != null)
                            {
                                list.Add(profile);
                            }
                        }
                        catch
                        {
                            // do nothing
                        }
                        ptr += (str.Length + 1) * 2;
                    }while (true);
                }
            }
            return(list);
        }
Example #2
0
 private static extern bool EnumColorProfiles(string pMachineName, ref ENUMTYPE pEnumRecord, IntPtr pEnumerationBuffer, ref int pdwSizeOfEnumerationBuffer, out int pnProfiles);