Google
 
Web itpro-blogger.blogspot.com
土曜日, 5月 17, 2008

[VB→C#]INIファイル関連(WIN32API)

▼質問
INIファイル関連の関数宣言を教えてくれ!

▼回答
サンプルを示しておくから参考にしてくれ!!

[VB]
' INIファイルから値を取得する関数の宣言
Public Declare Auto Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileString" ( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As StringBuilder, _
ByVal nSize As UInt32, _
ByVal lpFileName As String) As UInt32

' INIファイルから値を取得する関数の宣言
Public Declare Auto Function GetPrivateProfileInt Lib "kernel32" _
Alias "GetPrivateProfileInt" ( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal intDefault As Integer, _
ByVal lpFileName As String) As UInt32

' INIファイルに値を設定する関数の宣言
Public Declare Auto Function WritePrivateProfileString Lib "kernel32" _
Alias "WritePrivateProfileString" ( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpString As String, _
ByVal lpFileName As String) As UInt32

[C#]
// INIファイルから値を取得する関数の宣言
[DllImport("kernel32.dll")]
public static extern uint GetPrivateProfileString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedString,
uint nSize,
string lpFileName);

// INIファイルから値を取得する関数の宣言
[DllImport("kernel32.dll")]
public static extern uint GetPrivateProfileInt(
string lpAppName,
string lpKeyName,
int nDefault,
string lpFileName);

// INIファイルに値を設定する関数の宣言
[DllImport("kernel32.dll")]
public static extern uint WritePrivateProfileString(
string lpAppName,
string lpKeyName,
string lpString,
string lpFileName);






Comments: コメントを投稿

<< Home

This page is powered by Blogger. Isn't yours?