从 PowerPoint 中的 CustomLayoutsPtr 获取 CustomLayoutPtr API

Get CustomLayoutPtr from CustomLayoutsPtr in PowerPoint API

我正在尝试加载 pot 文件并根据需要使用其布局。

在VBA中是这样的:

    Sub setLayout()
    Call LoadDesign

    ActivePresentation.Slides(1).CustomLayout = ActivePresentation.Designs(1).SlideMaster.CustomLayouts(3)

    End Sub

    Sub LoadDesign()
        ActivePresentation.Designs.Load TemplateName:="C:\myPptTemplate.pot", Index:=1
    End Sub

在 C++ 中,我试过:

    PowerPoint::DesignPtr my_design= my_active_presentation->Designs->Load(as_bstr(template_filename), 1);
    PowerPoint::CustomLayoutsPtr my_layouts = my_design->SlideMaster->CustomLayouts;
    PowerPoint::CustomLayoutPtr my_layout = my_layouts->Item(_variant_t(1));

它在 VBA 中运行良好,但在 C++ 中却不行。 我无法从 my_layouts 获取 CustomLayoutPtr。它抛出异常 E_INVALIDARG.

如果您能分享我如何解决此问题的任何想法,我将不胜感激。

参考:

MSO API 2007

VS2008

解决方案是使用:

    long i=1;
    _variant_t index(i, VT_I4);

VT_I4 4 字节有符号整数。

在 32 位系统上,VT_INT 是一个 32 位有符号整数。

在 64 位系统上,VT_INT 是一个 64 位有符号整数。

我有一个 64 位的,但仍然 VT_INT 不工作。可能是一些内部问题。

希望对您有所帮助。