C#导入DLL的简单方法

//首先导入库
using System.Runtime.InteropServices;

//以kernel32.dll为例,其中的GetPrivateProfileString函数

//在类中声明一下即可
[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 void GetInt32(string Section, string Key, string Default, ref int Value)
{
    StringBuilder retVal = new StringBuilder(1024);
    GetPrivateProfileString(Section, Key, Default, retVal, 1024, this.Path);
    Value = Int32.Parse(retVal.ToString());
}


 

你可能感兴趣的:(C#)