예제 #1
0
        public void SetIniValue(string app, string key, StringBuilder value, string path)
        {
            var sb     = new StringBuilder(1000);
            var retVal = Win32IniApi.WritePrivateProfileString(app, key, value, path);

            if (!retVal && Win32IniApi.GetLastError() != 0)
            {
                throw new Exception("Cannot set value in ini file: " + Win32IniApi.GetLastError());
            }
        }
예제 #2
0
        public string GetIniValue(string app, string key, string defaultValue, string path)
        {
            var sb = new StringBuilder(1000);

            var retVal = Win32IniApi.GetPrivateProfileString(app, key, defaultValue, sb, (uint)sb.Capacity, path);

            if (retVal == 0)
            {
                var lastErr = Win32IniApi.GetLastError();
                if (lastErr != 0)
                {
                    if (lastErr == 2)
                    {
                        throw new Exception("Ini file '$Path' does not exist");
                    }
                    throw new Exception("Cannot get value from ini file: " + lastErr);
                }
            }

            return(sb.ToString());
        }