大家好,又见面了,我是你们的朋友全栈君。
using System.Runtime.InteropServices;
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retval, int size, string filePath);
[DllImport("kernel32")]
这叫引入kernel32.dll这个动态连接库。private static extern void 函数名(参数,[参数]);
[AttributeUsage(AttributeTargets.Method)]
public class DllImportAttribute: System.Attribute
{
public DllImportAttribute(string dllName) {…} //定位参数为dllName
public CallingConvention CallingConvention; //参数指示入口点的调用约定。如果未指定 CallingConvention,则使用默认值 CallingConvention.Winapi。
public CharSet CharSet; //参数指示用在入口点中的字符集。如果未指定 CharSet,则使用默认值 CharSet.Auto。
public string EntryPoint; //参数给出 dll 中入口点的名称。如果未指定 EntryPoint,则使用方法本身的名称。
public bool ExactSpelling; //参数指示 EntryPoint 是否必须与指示的入口点的拼写完全匹配。如果未指定 ExactSpelling,则使用默认值 false。
public bool PreserveSig; //参数指示方法的签名应当被保留还是被转换。当签名被转换时,它被转换为一个具有 HRESULT 返回值和该返回值的一个名为 retval 的附加输出参数的签名。如果未指定 PreserveSig,则使用默认值 true。
public bool SetLastError; //参数指示方法是否保留 Win32"上一错误"。如果未指定 SetLastError,则使用默认值 false。
public string Value { get {…} }
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/128400.html原文链接:https://javaforall.cn