CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  硬件/嵌入开发 >  嵌入开发(WinCE)

如何读取smartphone(如dopod)的机器码?

楼主gxlam()2005-03-10 15:33:25 在 硬件/嵌入开发 / 嵌入开发(WinCE) 提问

哪位大虾试验过,请指教! 问题点数:20、回复次数:1Top

1 楼aawolf(羌狼)回复于 2005-03-10 17:41:33 得分 20

private   static   Int32   METHOD_BUFFERED   =   0;  
                  private   static   Int32   FILE_ANY_ACCESS   =   0;  
                  private   static   Int32   FILE_DEVICE_HAL   =   0x00000101;  
   
                  private   const   Int32   ERROR_NOT_SUPPORTED   =   0x32;  
                  private   const   Int32   ERROR_INSUFFICIENT_BUFFER   =   0x7A;  
   
                   
                  private   static   Int32   IOCTL_HAL_GET_DEVICEID   =   ((FILE_DEVICE_HAL)   <<   16)   |   ((FILE_ANY_ACCESS)   <<   14)   |   ((21)   <<   2)   |   (METHOD_BUFFERED);  
   
                   
                  [DllImport("coredll.dll",   SetLastError=true)]  
                  private   static   extern   bool   KernelIoControl(Int32   dwIoControlCode,   IntPtr   lpInBuf,   Int32   nInBufSize,   byte[]   lpOutBuf,   Int32   nOutBufSize,   ref   Int32   lpBytesReturned);  
   
   
                  private   static   string   GetDeviceID()  
                  {  
   
   
                          //   Initialize   the   output   buffer   to   the   size   of   a   Win32   DEVICE_ID   structure  
                          byte[]   outbuff   =   new   byte[20];  
                          Int32     dwOutBytes;  
                          bool   done   =   false;  
   
                          Int32   nBuffSize   =   outbuff.Length;  
   
                          //   Set   DEVICEID.dwSize   to   size   of   buffer.     Some   platforms   look   at  
                          //   this   field   rather   than   the   nOutBufSize   param   of   KernelIoControl  
                          //   when   determining   if   the   buffer   is   large   enough.  
                          //  
                          BitConverter.GetBytes(nBuffSize).CopyTo(outbuff,   0);      
                          dwOutBytes   =   0;  
   
   
                          //   Loop   until   the   device   ID   is   retrieved   or   an   error   occurs  
                          while   (!   done)  
                          {  
                                  if   (KernelIoControl(IOCTL_HAL_GET_DEVICEID,   IntPtr.Zero,   0,   outbuff,   nBuffSize,   ref   dwOutBytes))  
                                  {  
                                          done   =   true;  
                                  }  
                                  else  
                                  {  
                                          int   error   =   Marshal.GetLastWin32Error();  
                                          switch   (error)  
                                          {  
                                          case   ERROR_NOT_SUPPORTED:  
                                                  throw   new   NotSupportedException("IOCTL_HAL_GET_DEVICEID   is   not   supported   on   this   device",   new   Win32Exception(error));  
   
                                          case   ERROR_INSUFFICIENT_BUFFER:  
                                                  //   The   buffer   wasn't   big   enough   for   the   data.     The  
                                                  //   required   size   is   in   the   first   4   bytes   of   the   output  
                                                  //   buffer   (DEVICE_ID.dwSize).  
                                                  nBuffSize   =   BitConverter.ToInt32(outbuff,   0);  
                                                  outbuff   =   new   byte[nBuffSize];  
   
                                                  //   Set   DEVICEID.dwSize   to   size   of   buffer.     Some  
                                                  //   platforms   look   at   this   field   rather   than   the  
                                                  //   nOutBufSize   param   of   KernelIoControl   when  
                                                  //   determining   if   the   buffer   is   large   enough.  
                                                  //  
                                                  BitConverter.GetBytes(nBuffSize).CopyTo(outbuff,   0);  
                                                  break;  
   
                                          default:  
                                                  throw   new   Win32Exception(error,   "Unexpected   error");  
                                          }  
                                  }  
                          }  
   
                          Int32   dwPresetIDOffset   =   BitConverter.ToInt32(outbuff,   0x4);         //   DEVICE_ID.dwPresetIDOffset  
                          Int32   dwPresetIDSize   =   BitConverter.ToInt32(outbuff,   0x8);             //   DEVICE_ID.dwPresetSize  
                          Int32   dwPlatformIDOffset   =   BitConverter.ToInt32(outbuff,   0xc);     //   DEVICE_ID.dwPlatformIDOffset  
                          Int32   dwPlatformIDSize   =   BitConverter.ToInt32(outbuff,   0x10);       //   DEVICE_ID.dwPlatformIDBytes  
                          StringBuilder   sb   =   new   StringBuilder();  
   
                          for   (int   i   =   dwPresetIDOffset;   i   <   dwPresetIDOffset   +   dwPresetIDSize;   i++)  
                          {  
                                  sb.Append(String.Format("{0:X2}",   outbuff[i]));  
                          }  
   
                          sb.Append("-");  
                          for   (int   i   =   dwPlatformIDOffset;   i   <   dwPlatformIDOffset   +   dwPlatformIDSize;   i   ++   )      
                          {  
                                  sb.Append(   String.Format("{0:X2}",   outbuff[i]));  
   
                          }  
                          return   sb.ToString();  
   
                  }  
  Top

相关问题

  • 深入机器码...
  • 生成机器码问题。
  • 如何取得机器码?
  • 如何更改机器码
  • 机器码的头大问题
  • 关于机器码的问题
  • 有关机器码的问题
  • 机器码时怎么回事?
  • 关于8086机器码的问题
  • 怎么样获得PDA的机器码?

关键词

  • hal
  • device
  • buffer
  • private static int
  • error
  • private const int

得分解答快速导航

  • 帖主:gxlam
  • aawolf

相关链接

  • CSDN Blog
  • 技术文档
  • 代码下载
  • 第二书店
  • 读书频道

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo