본문 바로가기

Delphi/꿀팁

PC의 MAC주소 가져오기

function GetMacAddress : string;

var

  UuidCreateFunc : function(var guid: TGUID): HRESULT; stdcall;

  hHandle : THandle;

  gGuid : TGUID;

  OSVer : TOSVersionInfo;

  I : Integer;

  hErrCode : HRESULT;

begin

  Result := '';


  OSVer.dwOSVersionInfoSize := SizeOf(OSVer);

  GetVersionEx(OSVer);


  hHandle := LoadLibrary('RPCRT4.DLL');

  if OSVer.dwMajorVersion >= 5 then

    @UuidCreateFunc := GetProcAddress(hHandle, 'UuidCreateSequential')

  else

    @UuidCreateFunc := GetProcAddress(hHandle, 'UuidCreate');


  UuidCreateFunc(gGuid);


  for I := 2 to 7 do

  begin

    if I = 2 then

      Result := Result + IntToHex(gGuid.d4[I], 2)

    else

      Result := Result + '-' + IntToHex(gGuid.d4[I], 2);

  end;


  FreeLibrary(hHandle);

end;


반응형