1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| Imports System.Runtime.InteropServices
Public Class MyClsAccessINI
<DllImport("kernel32", EntryPoint:="GetPrivateProfileStringW", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)> _
Private Shared Function GetPrivateProfileString(<MarshalAs(UnmanagedType.VBByRefStr)> ByRef lpApplicationName As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef lpKeyName As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef lpDefault As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef lpReturnedString As String, ByVal nSize As Integer, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef lpFileName As String) As Integer
End Function
<DllImport("kernel32", EntryPoint:="WritePrivateProfileStringW", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)> _
Private Shared Function WritePrivateProfileString(<MarshalAs(UnmanagedType.VBByRefStr)> ByRef lpApplicationName As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef lpKeyName As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef lpString As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef lpFileName As String) As Integer
End Function
Public Shared Sub INIDelete(ByVal INIPath As String, ByVal SectionName As String)
Dim lpKeyName As String = Nothing
Dim lpString As String = Nothing
MyClsAccessINI.WritePrivateProfileString(SectionName, lpKeyName, lpString, INIPath)
End Sub
Public Shared Sub INIDelete(ByVal INIPath As String, ByVal SectionName As String, ByVal KeyName As String)
Dim lpString As String = Nothing
MyClsAccessINI.WritePrivateProfileString(SectionName, KeyName, lpString, INIPath)
End Sub
Public Shared Function INIRead(ByVal INIPath As String) As String
Return MyClsAccessINI.INIRead(INIPath, Nothing, Nothing, "")
End Function
Public Shared Function INIRead(ByVal INIPath As String, ByVal SectionName As String) As String
Return MyClsAccessINI.INIRead(INIPath, SectionName, Nothing, "")
End Function
Public Shared Function INIRead(ByVal INIPath As String, ByVal SectionName As String, ByVal KeyName As String) As String
Return MyClsAccessINI.INIRead(INIPath, SectionName, KeyName, "")
End Function
Public Shared Function INIRead(ByVal INIPath As String, ByVal SectionName As String, ByVal KeyName As String, ByVal DefaultValue As String) As String
Dim lpReturnedString As String = Strings.Space(&H800)
Dim length As Integer = MyClsAccessINI.GetPrivateProfileString(SectionName, KeyName, DefaultValue, lpReturnedString, lpReturnedString.Length, INIPath)
If length > 0 Then
Return lpReturnedString.Substring(0, length)
End If
Return ""
End Function
Public Shared Sub INIWrite(ByVal INIPath As String, ByVal SectionName As String, ByVal KeyName As String, ByVal TheValue As String)
MyClsAccessINI.WritePrivateProfileString(SectionName, KeyName, TheValue, INIPath)
End Sub
End Class |
Partager