Delphi 获取Mac地址

来源:互联网 发布:南风知我意txt微盘 编辑:程序博客网 时间:2024/05/01 00:26
  1. function MacAddress: string;
  2. var
  3.   Lib: Cardinal;
  4.   Func: function(GUID: PGUID): Longint; stdcall;
  5.   GUID1, GUID2: TGUID;
  6. begin
  7.   Result := '';
  8.   Lib := LoadLibrary('rpcrt4.dll'); 
  9.   if Lib <> 0 then
  10.   begin
  11.     if Win32Platform <>VER_PLATFORM_WIN32_NT then
  12.       @Func := GetProcAddress(Lib, 'UuidCreate')
  13.       else @Func := GetProcAddress(Lib, 'UuidCreateSequential');
  14.     if Assigned(Func) then
  15.     begin
  16.       if (Func(@GUID1) = 0and
  17.         (Func(@GUID2) = 0and
  18.         (GUID1.D4[2] = GUID2.D4[2]) and
  19.         (GUID1.D4[3] = GUID2.D4[3]) and
  20.         (GUID1.D4[4] = GUID2.D4[4]) and
  21.         (GUID1.D4[5] = GUID2.D4[5]) and
  22.         (GUID1.D4[6] = GUID2.D4[6]) and
  23.         (GUID1.D4[7] = GUID2.D4[7]) then
  24.       begin
  25.         Result :=
  26.          IntToHex(GUID1.D4[2], 2) + '' +
  27.          IntToHex(GUID1.D4[3], 2) + '' +
  28.          IntToHex(GUID1.D4[4], 2) + '' +
  29.          IntToHex(GUID1.D4[5], 2) + '' +
  30.          IntToHex(GUID1.D4[6], 2) + '' +
  31.          IntToHex(GUID1.D4[7], 2);
  32.       end;
  33.     end;
  34.     FreeLibrary(Lib);
  35.   end;
  36. end;
 
原创粉丝点击