►index

     スポンサーサイト

    --------

    上記の広告は1ヶ月以上更新のないブログに表示されています。
    新しい記事を書く事で広告が消せます。

     VB.NET Windows INIファイル 操作(読み書き)クラス

    2013-06-12

    Windows Ini形式のファイルの読み込み、書き込みクラスです。

    Imports System.Text

    Namespace Dao

     

        Public Class WinIni

            Private Declare Function WritePrivateProfileString Lib "kernel32" _

                      Alias "WritePrivateProfileStringA" _

                      (ByVal lpApplicationName As String, ByVal lpKeyName As String, _

                      ByVal lpString As String, ByVal lpFileName As String) As Long

     

            Public Declare Auto Function GetPrivateProfileString Lib "kernel32" _

                      Alias "GetPrivateProfileString" ( _

                     <MarshalAs(UnmanagedType.LPTStr)> ByVal lpApplicationName As String, _

                     <MarshalAs(UnmanagedType.LPTStr)> ByVal lpKeyName As String, _

                     <MarshalAs(UnmanagedType.LPTStr)> ByVal lpDefault As String, _

                     <MarshalAs(UnmanagedType.LPTStr)> ByVal lpReturnedString As StringBuilder, _

                      ByVal nSize As UInt32, _

                     <MarshalAs(UnmanagedType.LPTStr)> ByVal lpFileName As String) As UInt32

     

            Sub IniWrt(ByVal IniSection As String, ByVal Inikey As String, _

                     ByVal IniValue As String, ByVal IniFilePath As String)

               

     

                Dim lngrtc As Long

                lngrtc = WritePrivateProfileString(IniSection, Inikey, IniValue, IniFilePath)

     

            End Sub

     

            Function IniRed(ByVal IniSection As String, ByVal Inikey As String, _

                     ByVal IniFilePath As String) As String

               

                Dim W As StringBuilder = New StringBuilder(1024)

     

                Dim ret As Long

                Dim strLine As String

                Dim rtc

     

     

                ret = GetPrivateProfileString(IniSection, Inikey, "", W, Convert.ToUInt32(W.Capacity), IniFilePath)

                strLine = W.ToString

     

                rtc = InStr(1, strLine, "'") 'コメント除去処理

                If rtc <> 0 Then

                    IniRed = Trim(Left(strLine, rtc - 1))

                Else

                    IniRed = Trim(strLine)

                End If

     

            End Function

     

        End Class

    End Namespace

     


    トラックバック

    コメントの投稿

    非公開コメント

    PR
    上記広告は1ヶ月以上更新のないブログに表示されています。新しい記事を書くことで広告を消せます。