我正在制作一个用于检测/检查树莓派是否已连接到任何wifi网络的应用程序。
如果设备已连接,则顶部的标签将显示已连接,如果未连接,则其将显示未连接。我正在使用Visual Studio 2019在Windows中进行编码。
现在,我在Windows中运行并运行该应用程序,但是当我使用mono在raspberry pi 3b中运行可执行文件时,它将在终端中产生很多错误。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace ConnectionStatus
{
public partial class Form1 : Form
{
[DllImport("wininet.dll")]
private extern static bool InternetgetconnectedState(out int conn,int val);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender,EventArgs e)
{
int Out;
if(InternetgetconnectedState(out Out,0) == true)
{
label1.Text = "Connected !";
label1.ForeColor = System.Drawing.Color.White;
panel1.BackColor = System.Drawing.Color.Green;
}
else
{
label1.Text = "Not Connected !";
label1.ForeColor = System.Drawing.Color.White;
panel1.BackColor = System.Drawing.Color.Red;
}
}
private void button1_Click(object sender,EventArgs e)
{
Application.Exit();
}
}
}
我认为我的错误是这些:
using System.Windows.Forms;
和
[DllImport("wininet.dll")]
private extern static bool InternetgetconnectedState(out int conn,int val);
我知道这将导致错误,因为它是为Windows编写的。 我的问题是我将用什么替换代码?顺便说一句,我正在运行一个树莓派。非常感谢您的帮助。