今天联系写INI文件。在调试时出现如下错误
找了半天,没弄明白怎么处理,或者太复杂了,查了下我的声明函数
//声明读写INI文件的API函数
[DllImport("kernel32")]
private static extern bool WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, byte[] retVal, int size, string filePath);
抱着幼稚的想法,是不是我的声明里没加.dll,在代码里加上试了一下
//声明读写INI文件的API函数
[DllImport("kernel32.dll")]
private static extern bool WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32.dll")]
private static extern int GetPrivateProfileString(string section, string key, string def, byte[] retVal, int size, string filePath);
重新生成后运行不再报错。
后面再新建一个把.dll删了重试,会提示修改代码,如果不改也能正常运行
是不是第一引入需要加.dll后缀。引入后就不需要了。