我正在研究一种读取INI文件内容的工具。我正在使用kernel32 dll import。但是,当我在实际设备上运行应用程序时,我得到一个像这样的异常,“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();
}
}
答案 0 :(得分:0)
支持最低客户端| Windows 2000 Professional [仅限桌面应用]
WritePrivateProfileString function (Windows)
另请查看以下链接:
Win32 and COM for Windows Store apps (system) (Windows)
WritePrivateProfileString() Does Not Work If You Do Not Have Delete Access on the Folder