How the ClassID of an OCX is determined?

Does someone know how the compiler decides what ClassId to give a certain OCX?
and how it guards that the number stays unique?
Who is Participating?
simonbennettConnect With a Mentor Commented:
Sorry msiman - I though you wanted to create a *new* GUID

If you need to change it you should use RegSetKeyValueEx etc API calls to look at the entry in the registry. If you look in..

HKEY_CLASSES_ROOT\YOURAPP.YOURCLASS\CLSID the registry you will find the GUID for the class yourapp.yourclass, e.g. i have


which stores


This is a string value so you can use...

Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long set it.


It uses a 128 bit 'random' generator that uses the system time, serial number, HD identifier and free bytes on the HD to produce the alphanumeric 'GUID' (globally unique identifier) - the same process can be seen for example in MS Access replication. The chanes of a duplicate are supposidly 10 to the power of 21 of a dupe occuring.

All Hail To Billy
msimanAuthor Commented:
So why everywhere i install my OCX, it keeps its

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Thats because it is created when it is compiled. Once created the GUID does not change. That process uses information from the development machine.
..sorry, depending on your compatability settings - i.e No Compatability will keep the guid the same for example...
msimanAuthor Commented:
I will refine my question, so i raised a little the points.
I want to be able to change the CLassID of an OCX manually.
is it possible? if yes, then  how?

Nope. And if you did it would be risky...
msimanAuthor Commented:
sorry, but it must be possible. the compiler does it,
what can't I?
the ClassID is stored somewhere, right? so
it can be changed with the appropriate editor....
and i want to do so...
msimanAuthor Commented:
first' it doesn't work.
i created 2 OCXes, and wrote a program that calls one of them,
then i erased the first one, renmaed the second to be
the first, change its GUID to the GUID of the first one,
and i got an error. both had the same programming interface.
second, i am much more interested to know wheree the GUID is stored in the file...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.