C#获取设备的ID浅谈

学习C#语言时,经常会遇到C#获取设备的ID问题,这里将介绍C#获取设备的ID问题的解决方法。

1.C#获取设备的ID(本地)

我们查看Window CE 4.2的SDK文档,得知获取本地设备ID的函数是BthReadLocalAddr,在btdrt.dll中。SDK文档中的英文原文是这样的:“This function retrieves the Bluetooth address of the current device.”好了,知道了这个就好说了:

首先封装本地托管函数:

 
 
 
  1. [DllImport("Btdrt.dll", SetLastError=true)]  
  2. public static extern int BthReadLocalAddr(byte[] pba);  
  3. //这个函数得到的本地DeviceID也是一组byte数组,为了向人们显示出来,我们要把它变为String:  
  4. string text1 = "";  
  5. text1text1 = text1 + pba[5].ToString("X2") + ":";  
  6. text1text1 = text1 + pba [4].ToString("X2") + ":";  
  7. text1text1 = text1 + pba [3].ToString("X2") + ":";  
  8. text1text1 = text1 + pba [2].ToString("X2") + ":";  
  9. 责任编辑:佚名 来源: 博客园 C#获取设备的ID
THE END