GetPrivateProfileString (kernel32)
Last changed: -131.107.0.95

.
Summary

C# Signature:

[DllImport("kernel32.dll")]
static extern uint GetPrivateProfileString(
   string lpAppName,
   string lpKeyName,
   string lpDefault,
   StringBuilder lpReturnedString,
   uint nSize,
   string lpFileName);

User-Defined Types:

None.

Notes:

To avoid casting of the StringBuilder.Capacity to uint you can also declare the nSize parameter as int.

Tips & Tricks:

Please add some!

Sample Code:

using System;
using System.Runtime.InteropServices;
using System.Text;
namespace GPPS
{
   class Class1
   {
     static void Main(string[] args)
     {
       StringBuilder sb = new StringBuilder(500);
       uint res = GetPrivateProfileString("AppName", "KeyName", "", sb, sb.Capacity, @"c:\test.ini");
       Console.WriteLine(sb.ToString());
     }
       [DllImport("kernel32.dll")]
       static extern uint GetPrivateProfileString(
     string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);
   }
}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation