Mr. Boy
Mr. Boy

Reputation: 63748

GUID/ProgId/CLSID confusion

Trying to track down a COM problem, I'm debugging my code and seeming to see the same GUID represented different ways...

I have a line in our code: class __declspec(uuid("{D4F83347-E58E-11d1-9D47-006008098294}"))

And various registry stuff in between, then a call to:

CLSID clsid;
::CLSIDFromProgID("myProgId",&clsid);

In the debugger, clsid is displayed as {000AFC9A-3347-D4F8-8EE5-D1119D470060}. To me this is too similar not to be right, but it's not something I can check automatically... we've got the D4F8 and 3347, 9D47, but E58E becomes 8EE5 etc.

Is there a way I can understand why this is happening, and a way I can get them to look the same for comparison?

EDIT To clear up some side-tracking, I've checked and the CLSID in the Windows registry and our registration scripts is presented as {D4F83347-E58E-11d1-9D47-006008098294} too - so the issue over my uuid(...) is not relevant I think.

Upvotes: 0

Views: 3071

Answers (3)

Mr. Boy
Mr. Boy

Reputation: 63748

After some testing, I discovered that the issue was simply how the visual C++ debugger was displaying the value, nothing more. e.g the registry value is {D4F83347-E58E-11d1-9D47-006008098294}, calling ::StringToCLSID() on the result of CLSIDFromProgID() gives {D4F83347-E58E-11d1-9D47-006008098294} - but in the debugger MSVC++ displays the variable as {000AFC9A-3347-D4F8-8EE5-D1119D470060}.

Why it does that, is another question!

Upvotes: 1

Roman Ryltsov
Roman Ryltsov

Reputation: 69687

"__declspec(uuid" is only an association of the identifier to your class, nothing else. Using CLSIDFromProgID API you are resolving ProgID to CLSID using registration infromation in system registry. That is, the two don't have to match. They typically do match though if you do everything neatly and your COM class is registered with the same identifier as the one being attached in source code to the C++ class.

Upvotes: 1

Hans Passant
Hans Passant

Reputation: 941635

Using CLSIDFromProgID() when you already have the guid doesn't make much sense. The function looks in the registry to map the "ProgId" string to the CLSID {guid}. Which of course makes it important that the progid is registered properly. Sure sounds like it is not. When your class is already decorated with __declspec(uuid) then simply use the __uuidof() operator to retrieve the guid.

The similarity in the byte values suggests that your registration code is broken.

Upvotes: 1

Related Questions