Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to create a (unique) GUID (2) Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
30-Aug-02
Category
System
Language
Delphi 3.x
Views
79
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I have a very simple piece of test code to generate and display a GUID on the 
screen every time a user clicks on a button on a form. When I compile the program 
and run the executable on my Windows 2000 machine, I get a unique GUID every time I 
click the button, which is what I expect from the documentation. However, when I 
run the same executable on any Windows 98 SE machine, and even a Windows NT 4.0 
Server (with SP5), it simply generates the exact same GUID over, and over, and over 
again.

Answer:

1   Using RAW API:
2   
3   { ... }
4   var
5     Form1: TForm1;
6     UuidCreateFunc: function(var guid: TGUID): HResult; stdcall;
7   
8   implementation
9   
10  {$R *.DFM}
11  
12  uses
13    ComObj;
14  
15  procedure TForm1.Button1Click(Sender: TObject);
16  var
17    hr: HRESULT;
18    m_TGUID: TGUID;
19    handle: THandle;
20  begin
21    handle := LoadLibrary('RPCRT4.DLL');
22    @UuidCreateFunc := GetProcAddress(Handle, 'UuidCreate');
23    hr := UuidCreateFunc(m_TGUID);
24    if failed(hr) then
25      RaiseLastWin32Error;
26    ShowMessage(GUIDToString(m_TGUID));
27  end;
28  
29  //With WIN2K support:
30  
31  { ... }
32  var
33    Form1: TForm1;
34    UuidCreateFunc: function(var guid: TGUID): HResult; stdcall;
35  
36  implementation
37  
38  {$R *.DFM}
39  
40  uses
41    ComObj;
42  
43  procedure TForm1.Button1Click(Sender: TObject);
44  var
45    hr: HRESULT;
46    m_TGUID: TGUID;
47    handle: THandle;
48    WinVer: _OSVersionInfoA;
49  begin
50    handle := LoadLibrary('RPCRT4.DLL');
51    WinVer.dwOSVersionInfoSize := sizeof(WinVer);
52    getversionex(WinVer);
53    if WinVer.dwMajorVersion >= 5 then {Windows 2000 }
54      @UuidCreateFunc := GetProcAddress(Handle, 'UuidCreateSequential')
55    else
56      @UuidCreateFunc := GetProcAddress(Handle, 'UuidCreate');
57    hr := UuidCreateFunc(m_TGUID);
58    if failed(hr) then
59      RaiseLastWin32Error;
60    ShowMessage(GUIDToString(m_TGUID));
61  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC