none
Get CustomLayoutPtr from CustomLayoutsPtr in PowerPoint API RRS feed

  • Question

  • I am trying to load a pot file and use its layouts depending on the requirements.

    In VBA it is something like this:

        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

    In C++, I tried:

        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));

    It is working fine in VBA, but not in C++. I cannot get a CustomLayoutPtr from my_layouts. It throws an exception E_INVALIDARG.

    I would be thankful if you share any ideas about how can I fix this issue.

    Ref:

    MSO API 2007

    VS2008

    Wednesday, February 18, 2015 10:35 AM

Answers

  • The solution is to use: 
    long i=1;
    _variant_t index(i, VT_I4);

    VT_I4 4-byte signed integer.
    On a 32-bit system, VT_INT is a 32-bit signed integer.
    On a 64-bit system, VT_INT is a 64-bit signed integer.

    I am having a 64-bits, but still VT_INT it didn't work. Maybe some internal issues.

    Hope it will help.
    Thursday, February 19, 2015 8:52 AM

All replies

  • Hello Zakaria,

    It looks like the issue is not related to PowerPoint. The parameter should be an OLEVariant object.

    Also I see that you pass different values to the CustomLayouts property: 3 in VBA, 1 in C++.

    You may find the C++ app automates PowerPoint (CppAutomatePowerPoint) sample project helpful.

    Wednesday, February 18, 2015 1:32 PM
  • Thanks a lot for your quick answer Eugene.

    The equivalent of OleVariant is VARIANT structure which is wrapped in _variant_t Class in Visual C++.

    The prototype of the function I am using. (copied from msppt.tlh)

        CustomLayoutPtr Item ( const _variant_t & Index );

    From the error, one may think it is just a small issue with the param. However, I have been trying many ways. Still the same.

    For the index 3<->1, I was using 3 before. I suppose the indexes will start from 0 or 1. If 3 works then 1 should work.

    I am already generating the ppt file. It works fine, but I would like to add this feature and use layouts from the .pot file.


    Wednesday, February 18, 2015 3:01 PM
  • The solution is to use: 
    long i=1;
    _variant_t index(i, VT_I4);

    VT_I4 4-byte signed integer.
    On a 32-bit system, VT_INT is a 32-bit signed integer.
    On a 64-bit system, VT_INT is a 64-bit signed integer.

    I am having a 64-bits, but still VT_INT it didn't work. Maybe some internal issues.

    Hope it will help.
    Thursday, February 19, 2015 8:52 AM