1 people like it.

WinAPI IniFile F# Interface

work with ini file with WritePrivateProfileString, GetPrivateProfileString easy as pie

 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: 
module Configuration

open System
open System.Collections.Generic
open System.Linq
open System.Text
open System.Runtime.InteropServices

module kernel =
    [<DllImport(@"kernel32")>]
    extern int64 WritePrivateProfileString(string section, string key, string v, string filePath);
    [<DllImport("kernel32")>]
    extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

type public IniFile(iNIPath : string) =
    let mutable path = iNIPath
    member X.Path
        with get() = path
        and set v = path <- v
    member X.IniWriteValue section key value =
        kernel.WritePrivateProfileString(section, key, value, X.Path)
    member X.IniReadValue section key =
        let temp = new StringBuilder(255)
        let i = kernel.GetPrivateProfileString(section, key, "", temp, 255, X.Path)
        temp.ToString()
module Configuration
namespace System
namespace System.Collections
namespace System.Collections.Generic
namespace System.Linq
namespace System.Text
namespace System.Runtime
namespace System.Runtime.InteropServices
Multiple items
type DllImportAttribute =
  inherit Attribute
  new : dllName:string -> DllImportAttribute
  val EntryPoint : string
  val CharSet : CharSet
  val SetLastError : bool
  val ExactSpelling : bool
  val PreserveSig : bool
  val CallingConvention : CallingConvention
  val BestFitMapping : bool
  val ThrowOnUnmappableChar : bool
  member Value : string

Full name: System.Runtime.InteropServices.DllImportAttribute

--------------------
DllImportAttribute(dllName: string) : unit
Multiple items
val int64 : value:'T -> int64 (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int64

--------------------
type int64 = Int64

Full name: Microsoft.FSharp.Core.int64

--------------------
type int64<'Measure> = int64

Full name: Microsoft.FSharp.Core.int64<_>
val WritePrivateProfileString : section:string * key:string * v:string * filePath:string -> int64

Full name: Configuration.kernel.WritePrivateProfileString
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = String

Full name: Microsoft.FSharp.Core.string
val section : string
val key : string
val v : string
val filePath : string
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
val GetPrivateProfileString : section:string * key:string * def:string * retVal:StringBuilder * size:int * filePath:string -> int

Full name: Configuration.kernel.GetPrivateProfileString
val def : string
Multiple items
type StringBuilder =
  new : unit -> StringBuilder + 5 overloads
  member Append : value:string -> StringBuilder + 18 overloads
  member AppendFormat : format:string * arg0:obj -> StringBuilder + 4 overloads
  member AppendLine : unit -> StringBuilder + 1 overload
  member Capacity : int with get, set
  member Chars : int -> char with get, set
  member Clear : unit -> StringBuilder
  member CopyTo : sourceIndex:int * destination:char[] * destinationIndex:int * count:int -> unit
  member EnsureCapacity : capacity:int -> int
  member Equals : sb:StringBuilder -> bool
  ...

Full name: System.Text.StringBuilder

--------------------
StringBuilder() : unit
StringBuilder(capacity: int) : unit
StringBuilder(value: string) : unit
StringBuilder(value: string, capacity: int) : unit
StringBuilder(capacity: int, maxCapacity: int) : unit
StringBuilder(value: string, startIndex: int, length: int, capacity: int) : unit
val retVal : StringBuilder
val size : int
Multiple items
type IniFile =
  new : iNIPath:string -> IniFile
  member IniReadValue : section:string -> key:string -> string
  member IniWriteValue : section:string -> key:string -> value:string -> int64
  member Path : string
  member Path : string with set

Full name: Configuration.IniFile

--------------------
new : iNIPath:string -> IniFile
val iNIPath : string
val mutable path : string
val X : IniFile
member IniFile.Path : string with set

Full name: Configuration.IniFile.Path
val set : elements:seq<'T> -> Set<'T> (requires comparison)

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.set
member IniFile.IniWriteValue : section:string -> key:string -> value:string -> int64

Full name: Configuration.IniFile.IniWriteValue
val value : string
module kernel

from Configuration
property IniFile.Path: string
member IniFile.IniReadValue : section:string -> key:string -> string

Full name: Configuration.IniFile.IniReadValue
val temp : StringBuilder
val i : int
StringBuilder.ToString() : string
StringBuilder.ToString(startIndex: int, length: int) : string
Next Version Raw view Test code New version

More information

Link:http://fssnip.net/dU
Posted:11 years ago
Author:nCdy
Tags: f# , ini , configuration