Reading INI file: Get Private Profile String : Native Windows Function « Windows « C# / CSharp Tutorial






using System;
using System.Runtime.InteropServices;
using System.Text;

class MainClass
{
    // Declare the unmanaged functions.
    [DllImport("kernel32.dll", EntryPoint = "GetPrivateProfileString")]
    private static extern int GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);


    static void Main(string[] args)
    {
        string section = "SampleSection"
        string key = "Key1";
        string filename = "\\initest.ini";

        int chars = 256;
        StringBuilder buffer = new StringBuilder(chars);
        string sDefault = "";
        if (GetPrivateProfileString(section, key, sDefault, buffer, chars, filename) != 0)
        {
            Console.WriteLine("Value of Key1 in [SampleSection] is: " + buffer.ToString());
        }
        else
        {
            Console.WriteLine("Value of Key1 in [SampleSection] is: " + null);
        }
    }
}








29.10.Native Windows Function
29.10.1.Calling Native DLL Functions
29.10.2.Calling a Function with a Structure Parameter
29.10.3.Enumerate Display Monitors
29.10.4.Get Workstation information
29.10.5.Get Computer name (char * parameter)
29.10.6.Get free disk space
29.10.7.Use native windows function to read file
29.10.8.The windows version information
29.10.9.Get current Active Window
29.10.10.Writing INI file: Write Private Profile String
29.10.11.Reading INI file: Get Private Profile String
29.10.12.GetVersionEx by using kernel32.dll
29.10.13.Get computer name (StringBuilder parameter)
29.10.14.Lock work station
29.10.15.Get Monitor Information