我正在将 d2d1_1.h 头文件移植到 Delphi,但卡在接口(interface)声明中。 在接口(interface)声明中,有调用的实际实现代码重新声明的方法。 这是一个示例(我只展示了代码的相关部分):
// d2d1_1.h line 1522
interface DX_DECLARE_INTERFACE("e8f7fe7a-191c-466d-ad95-975678bda998") ID2D1DeviceContext : public ID2D1RenderTarget
{
// d2d1_1.h line 1715
STDMETHOD_(void, SetRenderingControls)(
_In_ CONST D2D1_RENDERING_CONTROLS *renderingControls
) PURE;
// Lot of declarations ommited for simplicity
// d2d1_1.h line 2149
COM_DECLSPEC_NOTHROW
void
SetRenderingControls(
CONST D2D1_RENDERING_CONTROLS &renderingControls
)
{
return SetRenderingControls(&renderingControls);
}
}; // interface ID2D1DeviceContext
我理解第二个版本的功能只是为了方便编程。 实际上,实现给定接口(interface)的对象没有第二个版本的代码。 二进制级别的接口(interface)中没有插槽(接口(interface)实现为 指向方法的指针数组)。移植到 Delphi 时,我可以忽略第二个版本。 有人可以证实我的分析吗?
最佳答案
只有标有PURE
(定义为=0
)属性的方法真正存在于最终的COM vtable中。
其他方法是实用方法/包装器,包含只能在 C/C++ 中使用的 C/C++ 代码(它们将被编译),因此在使用其他语言(delphi、.NET 等)时不得声明它们.)
关于接口(interface)声明中的 C++ 实现代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63395535/