iniファイルの入出力

ページ名:iniファイルの入出力

Imports System.Runtime.InteropServices

''' <summary>
''' iniファイルの入出力
''' </summary>
''' <remarks></remarks>
Module mdlInit

    <DllImport("KERNEL32.DLL", CharSet:=CharSet.Auto)> _
    Public Function GetPrivateProfileString( _
       ByVal lpAppName As String, _
       ByVal lpKeyName As String, _
       ByVal lpDefault As String, _
       ByVal lpReturnedString As System.Text.StringBuilder, _
       ByVal nSize As Integer, _
       ByVal lpFileName As String) As Integer
    End Function

    <DllImport("KERNEL32.DLL")> _
    Public Function WritePrivateProfileString( _
       ByVal lpAppName As String, _
       ByVal lpKeyName As String, _
       ByVal lpString As String, _
       ByVal lpFileName As String) As Integer
    End Function

    Public Function pf_GetIni(ByVal wp_path As String, ByVal wp_section As String, ByVal wp_key As String, ByVal wp_Default As String) As String
        Dim ret As String = wp_Default
        Dim sb As New System.Text.StringBuilder
        sb.Capacity = 256
        Dim i As Integer = GetPrivateProfileString(wp_section, wp_key, wp_Default, sb, sb.Capacity, mf_path(wp_path))
        ret = sb.ToString
        Return ret
    End Function

    Public Sub ps_PutIni(ByVal wp_path As String, ByVal wp_section As String, ByVal wp_key As String, ByVal wp_value As String)
        Dim i As Integer = WritePrivateProfileString(wp_section, wp_key, wp_value, mf_path(wp_path))
    End Sub

    Private Function mf_path(ByVal wp_path As String) As String
        Dim ret As String = wp_path
        If ret = "" Then
            Dim w_path As String = Application.StartupPath
            If w_path.EndsWith("\") = False Then
                w_path = w_path & "\"
            End If
            ret = String.Format("{0}{1}.ini", w_path, My.Application.Info.AssemblyName)
        End If
        Return ret
    End Function

End Module
 

シェアボタン: このページをSNSに投稿するのに便利です。

コメント

返信元返信をやめる

※ 悪質なユーザーの書き込みは制限します。

最新を表示する

NG表示方式

NGID一覧