接口(interface)声明中的 C++ 实现代码

标签 c++ delphi interface direct2d

我正在将 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/

相关文章:

c++ - 我是否需要为 C++ 中的每个函数实现指定类

delphi - EXE 属性中未显示 VERSIONINFO 资源

.net - 如何将microsoft crm与delphi连接?

c# - Unity3d error CS1061 : Type x does not contain a definition for y. 但是确实如此吗?

c# - 谜语我这个 : why does the implicit interface implementation error occur?

java - 使用泛型/继承组合不同类型的命令接口(interface)

c++ - 这个简单的 C++ 程序是多线程的吗?

c++ - OpenCV 束调整

c++ - 如何在数组中添加以下内容?

delphi - 如何以及在哪里可以在使用 Android 的 Embarcadero Delphi XE5 中编写 ARM 汇编代码?