国产毛片a精品毛-国产毛片黄片-国产毛片久久国产-国产毛片久久精品-青娱乐极品在线-青娱乐精品

查看: 8276|回復(fù): 0
打印 上一主題 下一主題

C#下采用索引對(duì)WinIO的封裝類(WinIO.cs)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
發(fā)表于 2009-4-3 00:10:04 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
關(guān)鍵詞: WinIO , 封裝 , 索引
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;//MessageBox需要
using System.Runtime.InteropServices;//加動(dòng)態(tài)鏈接庫(kù)需要
//菜農(nóng)HotPower@126.com  2008.11.12 于雁塔村
namespace WindowsFormsApplication2
{
    #region C#下采用索引對(duì)WinIO的封裝類(WinIO.cs)
    /*
       應(yīng)用時(shí)應(yīng)該在Form1.cs中加入:
       private WinIO WinIOPort = new WinIO();
            例: WinIOPort[0x378] = 0x55;
                 x = WinIOPort[0x379, 2];
    */
    public class WinIO
    {
        //動(dòng)態(tài)鏈接庫(kù)的引用
        [DllImport("winio.dll")]
        public static extern bool InitializeWinIo();
        [DllImport("winio.dll")]
        public static extern void ShutdownWinIo();
        [DllImport("winio.dll")]
        public static extern bool GetPortVal(IntPtr wPortAddr, out uint pdwPortVal, byte
bSize);
        [DllImport("winio.dll")]
        public static extern bool SetPortVal(IntPtr wPortAddr, IntPtr dwPortVal, byte
bSize);
        /*
        //以下是WinIO與并口無(wú)關(guān)的函數(shù)
                    [DllImport("winio.dll")]
                    public static extern byte MapPhysToLin(byte pbPhysAddr, uint dwPhysSize,
IntPtr PhysicalMemoryHandle);
                    [DllImport("winio.dll")]
                    public static extern bool UnmapPhysicalMemory(IntPtr
PhysicalMemoryHandle, byte pbLinAddr);
                    [DllImport("winio.dll")]
                    public static extern bool GetPhysLong(IntPtr pbPhysAddr, byte
pdwPhysVal);
                    [DllImport("winio.dll")]
                    public static extern bool SetPhysLong(IntPtr pbPhysAddr, byte
dwPhysVal);
                    [DllImport("user32.dll")]
                    public static extern int MapVirtualKey(uint Ucode, uint uMapType);
        */
        //屬性字段
        private bool enable = false;//WinIO不可用
        private bool error = false;//讀寫出錯(cuò)字段
        public WinIO()
        {//構(gòu)造函數(shù)(自動(dòng)運(yùn)行)
            try
            {
                enable = InitializeWinIo();//加載WinIO
            }
            catch (System.Exception error)
            {//WinIO加載失敗異常處理
                MessageBox.Show(error.Message, "系統(tǒng)提示", MessageBoxButtons.OK,
MessageBoxIcon.Error);
            }
        }
        ~WinIO()
        {//析構(gòu)函數(shù)(自動(dòng)運(yùn)行)
            if (enable)
            {//成功加載WinIO
                ShutdownWinIo();//卸載WinIO
            }
        }
        public bool Enable
        {//Enable只讀屬性
            get
            {
                return enable;
            }
        }
        public bool Error
        {//Error只讀屬性
            get
            {
                return error;
            }
        }
        public byte this[uint index]//byte讀寫端口
        {//數(shù)組索引:
            get
            {//例如 x = WioIOPort[0x378];  等效:x = WioIOPort[0x378, sizeof(byte)];
                uint val;//WinIo要求dword
                error = GetPortVal((IntPtr)index, out val, sizeof(byte));
                return (byte)val;
            }
            set
            {//例如 WioIOPort[0x378] = 0xff; 等效:WioIOPort[0x378, sizeof(byte)] = 0xff;
                error = SetPortVal((IntPtr)index, (IntPtr)value, sizeof(byte));
            }
        }
        public uint this[uint index, byte size]//可用byte,word,dword讀寫端口
        {//數(shù)組索引,size=1/2/4=sizeof(byte/UInt16/UInt32)
            get
            {//例如 x = WioIOPort[0x378, sizeof(UInt16)];
                uint val;//WinIo要求dword
                error = GetPortVal((IntPtr)index, out val, size);
                return val;
            }
            set
            {//例如 WioIOPort[0x378, sizeof(UInt32)] = 0x12345678;
                error = SetPortVal((IntPtr)index, (IntPtr)value, size);
            }
        }
    }
    #endregion
}

本版積分規(guī)則

關(guān)于我們  -  服務(wù)條款  -  使用指南  -  站點(diǎn)地圖  -  友情鏈接  -  聯(lián)系我們
電子工程網(wǎng) © 版權(quán)所有   京ICP備16069177號(hào) | 京公網(wǎng)安備11010502021702
快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 青青操视频在线免费观看 | 青青色在线 | 久久黄色片 | 欧美一级日韩在线观看 | 久久99精品综合国产首页 | 青青久草| 狠狠操导航 | 日日夜夜摸 | 亚洲综合激情网 | 国产欧美日韩精品第二区 | 免费看污黄网站 | 国产免费久久精品99久久 | 免费看动漫强人物动漫的 | 亚洲男女免费视频 | 午夜a级理论片在线播放一级 | 男人色网站 | 精精国产www视频在线观看免费 | 亚洲六月婷婷 | 在线高清一级欧美精品 | 日韩免费在线看 | 天天操天天摸天天爽 | 久久机热这里只有精品 | 亚洲人妖ts资源在线观看 | 在线a毛片免费视频观看 | 亚洲大尺度在线观看 | 色综合天天综合 | 91免费精品国自产拍在线可以看 | 4虎永免费最新永久免费地址 | 羞羞视频免费看网站 | 国产毛片高清 | 自拍亚洲欧美 | 亚洲第一区精品观看 | 青青在线| 九九热在线免费观看 | 日韩欧美在线视频一区二区 | 日本成人免费在线观看 | 日干夜干天天干 | 思久久 | 国产精品hd | 九九在线观看高清免费 | 我与么公激情性完整视频 |