C# console app 실행하기 64 비트 Vista에 썼습니다. 코드는 다음과 같습니다.pinvoke를 통해 GetPrivateProfileString을 사용할 수없는 이유는 무엇입니까?
class Class1
{
static void Main(string[] args)
{
Debug.Assert(File.Exists(@"c:\test.ini"));
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);
}
큰 "DUH!" 대답은 없지만 왜 이것이 실패하는지 보지 못합니다. Debug.Assert 이외에,이 코드 pinvoke.net에 따르면 this page
내가 XP Pro 32 비트에서이 코드를 실행하고 있음을 잊어 버렸습니다. – Lee
방금 GetPrivateProfileSectionW 및 GetPrivateProfileSectionNamesW를 시도했습니다. 둘 다 같은 방식으로 실패합니다. 흥미로운 점은 섹션 이름을 검색하려고 할 때 GetPrivateProfileStringW 또는 GetPrivateProfileSectionNamesW를 사용하여 가져온 첫 번째 섹션 만 반환된다는 것입니다. 나는 이것들을 충분히 재미있게 보냈다. CodePlex는 몇 가지 대체품이있는 것처럼 보입니다. 그 두 가지가 작동하지 않는다면 나는 내 자신을 굴릴 것이다. – Lee
오 마이 맙소사! 네가 옳아! 내가 읽으려는 섹션은 INI 파일의 첫 번째 라인이 될 수 없습니다! 믿을 수 없는! 누가 알았겠습니까? 정말 고맙습니다. – Charles