C#调用 inpout32.dll 操作 CPU 的并口

//新建一个窗体程序后,放置两个按钮控件,分别把按钮控件名字修改为 InButton/OutButton ,双击按钮跳转

/*
***需要添加的头文件头文件****/ using System; using System.Runtime.InteropServices; /**************************/ /* 操作前要把 inpout32.dll 复制到你的项目文件夹 */ namespace Test_App { public partial class Form1 : Form { /*需要添加的:声明外部DLL调用*/ [DllImport("inpout32.dll", EntryPoint = "Out32")] public static extern void Output(int adress, int value); [DllImport("inpout32.dll", EntryPoint = "Inp32")] public static extern int Input(int adress); public Form1() { InitializeComponent(); } /*按钮控制输入*/ private void InButton_Click(object sender, EventArgs e) { Input( 888 );//添加控制读取代码,从888(即0x378)端口读取数据 } /*按钮控制输出*/ private void OutButton_Click(object sender, EventArgs e) { Output( 888, 4 );//添加控制输出代码,把4从888端口输出 } }
原文地址:https://www.cnblogs.com/xingboy/p/15011514.html