|
Interfaces without a GUID |
Top Previous Next |
|
What is translated > Types > Records, Classes, Interfaces > Interfaces > Non-generic interfaces > GUID's > Interfaces without a GUID In Delphi, it is valid to declare an interface without a GUID. In C++, however, every interface requires a GUID to support QueryInterface, Supports, and as_di<T>. Delphi2Cpp therefore automatically generates a GUID for any interface that has no GUID and is not a generic overload.
Example:
type IMyInterface = interface procedure SayHello; end;
Portable C++ (auto-generated GUID):
struct D2C_UUID("2744B454-2406-4EBA-A559-820560D1017F") IMyInterface: public virtual System::IInterface // ancestor added by Delphi2Cpp : public IInterface { virtual void SayHello() = 0; };
#ifdef IS_PORTABLE DEFINE_UUIDOF(IMyInterface, "57B95C48-0729-4798-9666-B037B77A203A") #endif // IS_PORTABLE
D2C_UUID expands to __declspec(uuid(...)) under MSVC and to nothing elsewhere.
Automatically generated GUIDs can be written to the options file and reapplied in subsequent translations to ensure consistency across builds.
Disabling GUID generation for specific interfaces:
By assigning an empty string "" to a given interface name in the options, Delphi2Cpp will not generate a GUID for that interface. This can be useful when the interface is purely internal and never used with Supports or QueryInterface.
|
|
This page belongs to the Delphi2Cpp Documentation |
Delphi2Cpp home Content |