如何DllImport 一个DLL?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace DLL
{
public class UserPowerDll
{
[DllImport("CDSkey.dll", CharSet = CharSet.Auto)]
public static extern bool GetSysPower; //报错修饰“extern”对该项无效?为什么会报这个错误呀。
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (UserPowerDll.GetSysPower)
{ MessageBox("Yes"); }
else { MessageBox("No"); }
}
}
}
如上代码:extern 报错。