Dangers of using the same GUID in interface definitions?

Let's pretend that:

1) HelpfulUserAtSO answers my SO question with a snippet copied from its production code:

type IReqBase = Interface(IInterface) ['{B71BD1C3-CE4C-438A-8090-DA6AACF0B3C4}'] procedure FillWithTemplateData; end; 

2) I think a great answer! and blindly copy this into my production code.

3a) We both distribute our applications, and user X wants to install both executable files on his computer.
What are the implications?

3b) I am buying HelpfulUserAtSO and want to integrate my code (containing the interface definition) into mine (containing the copy. What are the consequences?

In the end, the GUID must be "globally unique" ...

+4
source share
1 answer

If the same GUID is not used within the same process, it is safe for the same GUID to be defined. But if, for example, you access them through COM, this is completely confusing.

If you use different interfaces with the same GUID in the same process, for example, separating the blocks of Delphi code, you may finally have problems. By convention, a unique GUID must define a unique signature (i.e., a Set of methods), so the code may think that this instance of the class implements all the methods of the interface, and this is not so. As a result, the internal execution search (IMT) tables will not match. When calling methods, you will get a lot of A / V.

IMT interface table

Have a look at this very complete article to find out how interfaces work and what this internal IMT lookup table is for. The same GUID will mean the same IMT table, which will not be the case for you, so it just breaks at runtime.

+3
source

Source: https://habr.com/ru/post/1496105/


All Articles