Lazarus中文社区

 找回密码
 立即注册(注册审核可向QQ群索取)

QQ登录

只需一步,快速开始

Lazarus IDE and 组件 下载地址版权申明
查看: 1991|回复: 0

使用Lazarus在WINCE上获取设备ID和设备名称的例子

[复制链接]

该用户从未签到

发表于 2013-6-8 13:35:23 | 显示全部楼层 |阅读模式
获取设备ID:
  1. function GetDeviceUniqueID(AppData:LPCWSTR; cbApplictionData:Integer; dwDeviceIDVersion:Integer;
  2. var deviceIDOuput; var pcbDeviceIDOutput:DWORD):Integer; external 'coredll.dll' name 'GetDeviceUniqueID';

  3. function GetDeviceID: string;
  4. var
  5.   AppData: array[0..19] of WideChar;
  6.   DeviceID : array[0..19] of Byte;
  7.   Count: DWORD;
  8.   s: string;
  9.   Res, i:Integer;
  10. begin
  11.   //not sure about Unicode
  12.   AppData := Utf8Decode('MY_SIG');//any string you like
  13.   Count := SizeOf(DeviceID);
  14.   FillChar(DeviceID, Count, #0);
  15.   Res := GetDeviceUniqueID(AppData, SizeOF(AppData), 1, DeviceID, Count);
  16.   if Res = 0 then
  17.   begin
  18.     Result := '';
  19.     for i := 0 to Count -1 do
  20.     begin
  21.       if (i > 0) and ((i mod 2) = 0) then
  22.         Result := Result + '-'; //add space make the string wrap in label
  23.       Result := Result + IntToHex(DeviceID[i], 2);
  24.     end;
  25.   end
  26.   else
  27.     Result := '';//error accord
  28. //  you can MD5 it with your string
  29. //  Result := MD5Print(MD5Buffer(DeviceID, Count));
  30. end;
复制代码
获取设备名称:
  1. function GetDeviceName: string;
  2. var
  3.   aReg:TRegistry;
  4. begin
  5.   aReg := TRegistry.Create(KEY_READ);
  6.   try
  7.     aReg.RootKey := HKEY_LOCAL_MACHINE;
  8.     aReg.OpenKey('Ident', False);
  9.     if aReg.ValueExists('Name') then
  10.       Result := aReg.ReadString('Name')
  11.     else
  12.       Result := 'GUEST';
  13.   finally
  14.     aReg.Free;
  15.   end;
  16. end;
复制代码
回复

使用道具 举报

*滑块验证:

本版积分规则

QQ|手机版|小黑屋|Lazarus中国|Lazarus中文社区 ( 鄂ICP备16006501号-1 )

GMT+8, 2025-5-2 20:34 , Processed in 0.025046 second(s), 10 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表