C# 调用API函数创建INI文件

1.首先导入命名空间:using System.Runtime.InteropServices;

2.声明API函数:

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

3.创建ini文件:

       WritePrivateProfileStirng(section,key,value,filepath);

4.读取ini文件:

        StringBuilder temp=new StringBuilder();
        GetPrivateProfileString(section,key,default,temp,255,filepath);

 

 

 

 

posted @ 2013-04-08 22:52  Mr_4  阅读(252)  评论(0)    收藏  举报