日期:2014-05-19  浏览次数:20749 次

如何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   报错。

------解决方案--------------------
参数也要出来吧
------解决方案--------------------
[DllImport( "CDSkey.dll ", CharSet = CharSet.Auto)]
public static extern bool GetSysPower();