|
<< Click to Display Table of Contents >> ActiveSync - saber se celular está conectado |
![]() ![]()
|
Sem usar o OpenNETCF
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 CheckIfDeviceConnected
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("rapi.dll")]
public static extern void CeRapiInitEx(ref RAPIINIT pRapiInit);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern Int32 CeRapiUninit();
[StructLayout(LayoutKind.Sequential)]
public struct RAPIINIT
{
public int cbsize;
public IntPtr heRapiInit;
public UInt32 hrRapiInit;
};
private void btnCheck_Click(object sender, EventArgs e)
{
try
{
RAPIINIT r = new RAPIINIT();
r.cbsize = Marshal.SizeOf(r);
CeRapiInitEx(ref r);
if (r.hrRapiInit==0)
{
MessageBox.Show("Device is connected");
}
else
{
MessageBox.Show("Device is not connected");
}
}
finally
{
CeRapiUninit();
}
}
}
}