API - criando uma GUID

Top  Previous  Next

// criando uma GUID

 

var

  Form1: TForm1;

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

 

implementation

 

{$R *.dfm}

uses ComObj;

 

procedure TForm1.Button1Click(Sender: TObject);

var

  hr:HRESULT;

  m_TGUID:TGUID;

  handle : THandle;

  WinVer:_OSVersionInfoA;

begin

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

 

  WinVer.dwOSVersionInfoSize := sizeof(WinVer);

  getversionex(WinVer);

 

  if WinVer.dwMajorVersion >= 5 then {Windows 2000 }

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

  else

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

 

  hr:=UuidCreateFunc(m_TGUID);

  if failed(hr) then RaiseLastWin32Error;

  ShowMessage(GUIDToString(m_TGUID));

end;