为什么我不能得到GetPrivateProfileString通过PInvoke的工作? [英] Why can't I get GetPrivateProfileString to work via pinvoke?

查看:179
本文介绍了为什么我不能得到GetPrivateProfileString通过PInvoke的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行C#控制台应用程序,我写了64位Vista。这里的code:

Running a c# console app I wrote on 64 bit Vista. Here's the code:

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);
}

我敢肯定,我会得到一个大大的杜!一个答案,但我没有看到为什么这无法工作。除了Debug.Assert的,这code,从C#的样品切成此页

推荐答案

此人被整天破坏我扒了。我想我找到了一个解决方法,我真的不希望有处理:在您的.ini文件中的第一个节头前插入一个空行。现在运行你的应用程序,看看如果你不开始看到你期望的值。

This one has been busting my chops all day, too. I think I found a work-around, which I really don't want to have to deal with: insert a blank line before the first section header in your .ini file. Now run your app and see if you don't start seeing the values you were expecting.

考虑到这个bug显然已经好几年了,我很惊讶MS已经不是现在固定它。但随后,.ini文件被认为已经消失年前。这当然是有趣,因为有很多地方MS使用.ini文件(例如,的desktop.ini)。但是,我认为微软已经意识到错误的,因为我发现我的desktop.ini文件,包括领先的空行。嗯...

Considering this bug has apparently been around for years, I'm surprised MS hasn't fixed it by now. But then, .ini files were supposed to have gone away years ago. Which of course is funny, because there are a lot of places MS uses .ini file (e.g, desktop.ini). But I think MS is aware of the bug, because I notice my desktop.ini files include a leading blank line. Hmmm...

这篇关于为什么我不能得到GetPrivateProfileString通过PInvoke的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆