Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have learned that GUIDs should be unique on a PC. thats why we use GUID Generator in VS.

Lets suppose that we create a COM file with some interface with particular GUID which is unique on our PC.

Now when i transfer this COM file to some other PC, it might contains same GUID in the registry.

Then it will be a trouble.

I think i am wrong somewhere with my concepts. need help...?
Posted

I'm not sure how to respond to this, except to point out that the reason it's such a long string, is that Microsoft designed it precisely this way so that each GUID that is generated, will be unique. I've never, in over 10 years in the industry, heard of a COM component ever finding it has the same GUID as another. There's a GUID generator provided with Visual Studio. MS suggests if you just make them up instead of using that, you may be at some small risk, but if you generate your GUIDs the right way, there's no real risk of that ever happening. Especially now that almost no-one uses COM anymore :P
 
Share this answer
 
Comments
Aoi Karasu 21-Jun-11 6:59am    
IMO best answer out of five I've read here.
Sergey Alexandrovich Kryukov 21-Jun-11 18:06pm    
Agree, my 5, but I want to emphasize: the fact of world uniqueness is still probabilistic. There is not absolute theoretical guarantee for that. From most practical purposes the probability of coincidence is low enough.
--SA
TRK3 21-Jun-11 19:41pm    
I believe the algorithm for generating a GUID was originally specified to include the MAC address of your PC (which is guaranteed unique by the network card manufacturer), so that GUID's generated on different PC's were guaranteed to be unique, and the only danger of duplicate id's were GUID's generated on the same pc. If you were actually worried about it you would keep a record of all GUID's ever created on that pc and ensure they were unique there.
Emilio Garavaglia 22-Jun-11 7:57am    
Yes, this was the initial thinking. But it fails in the assumptions: MACs aren't unique. There are simply not enough of them to track all the network adapters existed in the history. Manufacturer recycles them, assuming an "old released MAC" doesn't exist anymore. But this is something they cannot know for certain. hence the "high improbability", instead of "impossibility".
But a GUID also contains a timestamps. Even admitting the reuse of a MAC ... it will probably leave on a different timeframe.
Harmanjeet Singh 22-Jun-11 13:30pm    
A lot discussion done on this topic. Got some Pros some Cons by various members and my friends, from the discussion, still not reach at the final solution on this.
The thinking of MACs is really a good solution if its actually done in reality. But my friend is also negating this solution... huh :) So many different paths, which to choose... :D
Unique ID is a 32 bit hexadecimal string and unique combination that is being created is 2 raise to 128. It is randomly created and not possible to create the same number twice.

I am using COM component for last 5 year and not facing any issue regarding GUID.
 
Share this answer
 
Comments
Sandeep Mewara 23-Jun-11 5:41am    
Countered your 1 vote.
ShilpiP 23-Jun-11 5:50am    
Thanks Sandeep :)
Hello

GUID is unique only. In any case it gets duplicated on other machine then go to tools and generate new GUID.

sanjeev
 
Share this answer
 
as has been noted by a number of other people, you're not going to get a GUID clash as long as you use the appropriate GUID generation functions CoCreateGuid, UuidCreate etc. If you roll your own GUID then all bets are off ...

That said, even if you DO get a GUID clash, the two exposures are
1. CLSID - you'll ask the 'wrong' class factory to give you an interface it doesn't support - E_NOTINTERFACE
2. IID - bugs will only present if you're using marshalling, and either interface has declared a PS marshalelr

Seriously, let it go ... don't worry about it - considerably more software than you'll ever be involved with will go belly up if GUIDs ever clash
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900