Created
March 17, 2015 11:17
-
-
Save yyamasak/445eb591a773ee4eefd6 to your computer and use it in GitHub Desktop.
GetPrivateProfileSectionNames.exe .\system.ini
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Runtime.InteropServices; | |
using System.IO; | |
namespace TestGetPrivateProfileSectionNames | |
{ | |
public class Program | |
{ | |
[DllImport("kernel32.dll")] | |
static extern int GetPrivateProfileSectionNames( | |
IntPtr lpszReturnBuffer, | |
uint nSize, | |
string lpFileName); | |
public static void Main(string[] args) | |
{ | |
string path = ""; | |
if (args.Length > 0) | |
{ | |
path = args[0]; | |
} | |
else | |
{ | |
path = @".\system.ini"; | |
} | |
if (File.Exists(path)) | |
{ | |
Console.WriteLine("INI file exists. {0}", path); | |
} | |
else | |
{ | |
Console.WriteLine("INI file missing. {0}", path); | |
} | |
IntPtr ptr = Marshal.StringToHGlobalAnsi(new String('\0', 1024)); | |
int length = GetPrivateProfileSectionNames(ptr, 1024, path); | |
if (0 < length) | |
{ | |
string result = Marshal.PtrToStringAnsi(ptr, length); | |
Array.ForEach<string>(result.Split('\0'), s => Console.WriteLine(s)); | |
} | |
Marshal.FreeHGlobal(ptr); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment