ファイル入出力
- INIファイル入出力
INIファイルに値を入出力します。ファイルパスは絶対パスとして下さい。相対パスを指定するとWindowsフォルダからの相対パスとなってしまいます。
[System.Runtime.InteropServices.DllImport( "KERNEL32.DLL" )]
public static extern uint GetPrivateProfileString( string lpAppName,
string lpKeyName, string lpDefault, StringBuilder lpReturnedString, uint nSize, string lpFileName );
[System.Runtime.InteropServices.DllImport( "KERNEL32.DLL" )]
public static extern uint GetPrivateProfileInt( string lpAppName,
string lpKeyName, int nDefault, string lpFileName );
[System.Runtime.InteropServices.DllImport( "KERNEL32.DLL" )]
public static extern uint WritePrivateProfileString( string lpAppName,
string lpKeyName, string lpString, string lpFileName );
public void Method()
{
uint nRet;
string szPath = @"C:\Sample.ini";
//--------------------------------------------
// 書き込み
WritePrivateProfileString( "APP1", "KEY1", "1", szPath );
//--------------------------------------------
// 読み取り
nRet = GetPrivateProfileInt( "APP1", "KEY1", 2, szPath );
StringBuilder szValue = new StringBuilder( 1024 );
nRet = GetPrivateProfileString( "APP1", "KEY1", "2", szValue, 1024, szPath );
}