using System; using System.Text; using System.Runtime.InteropServices; namespace CSVDownloader.File { class ConfigReader : IConfigReader{ [DllImport("kernel32.dll", EntryPoint = "GetPrivateProfileStringW", CharSet = CharSet.Unicode, SetLastError = true)] static extern uint GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, uint nSize, string lpFileName); private String filepath_; private uint buff_size = 256; /// /// ファイルパスを設定する /// /// public ConfigReader(String filepath) { filepath_ = filepath; } /// /// ファイルの値を取得する /// /// セクション名 /// キー名 /// 取得値 public String Read(String section, String key) { StringBuilder sb = new StringBuilder(Convert.ToInt32(buff_size)); GetPrivateProfileString(section, key, "", sb, buff_size, filepath_); return sb.ToString(); } } }