1

我正在开发一个读取 INI 文件内容的工具。我在其中使用 kernel32 dll 导入。但是,当我在实际设备上运行该应用程序时,我会收到这样的异常,“MethodAccessException:尝试访问该方法失败。” 我使用的设备是三星 Omnia (Windows Phone 7.1)。

除此之外,在另一个应用程序中,我正在使用核心 dll 导入,并且遇到了同样的异常。如何删除此异常?

public class IniFile
{
    public string path;

    [DllImport("kernel32")]
    private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
    [DllImport("kernel32")]
    private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

    public IniFile(string INIPath)
    {
        path = INIPath;
    }

    public void IniWriteValue(string Section, string Key, string Value)
    {
        WritePrivateProfileString(Section, Key, Value, this.path);
    }

    public string IniReadValue(string Section, string Key)
    {
        StringBuilder temp = new StringBuilder(255);
        int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
        return temp.ToString();
    }
}
4

1 回答 1

0

Minimum supported client | Windows 2000 Professional [desktop apps only]

WritePrivateProfileString function (Windows)

Also check this links:

Win32 and COM for Windows Store apps (system) (Windows)

WritePrivateProfileString() Does Not Work If You Do Not Have Delete Access on the Folder

于 2012-12-05T12:07:43.213 回答