Skip to content

Instantly share code, notes, and snippets.

@284km
Created February 10, 2014 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 284km/8912899 to your computer and use it in GitHub Desktop.
Save 284km/8912899 to your computer and use it in GitHub Desktop.
c# での ini ファイル読み込み
using System.Runtime.InteropServices;
public class xxxController
{
private const string XXX = "xxx";
[DllImport("KERNEL32.DLL")]
public static extern uint
GetPrivateProfileString(string lpAppName,
string lpKeyName, string lpDefault,
StringBuilder lpReturnedString, uint nSize,
string lpFileName);
public void xxx()
{
string iniFileName = AppDomain.CurrentDomain.BaseDirectory + "xxx\\yyy.ini";
// iniファイルから文字列を取得
StringBuilder sb = new StringBuilder(1024);
GetPrivateProfileString(
"category", // セクション名
"category", // キー名
"", // 値が取得できなかった場合に返される初期値
sb, // 格納先
Convert.ToUInt32(sb.Capacity), // 格納先のキャパ
iniFileName); // iniファイル名
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment