Question

I'm learning C++ PowerPoint automation basing on this sample code

http://code.msdn.microsoft.com/office/CppAutomatePowerPoint-024b696c/sourcecode?fileId=52793&pathId=1940694257

Everything looks clear to me, but I've got problem when I'm trying to change default template to my custom template saved on disk. I wrote following line:

AutoWrap(DISPATCH_METHOD, NULL, pPres, L"ApplyTheme", 1, L"D:\\template.thmx" ); 

which is reproduction of this working line from VBA:

Call pptPres.ApplyTheme("D:\template.thmx")

The problem is that application is crashing on this line.

Edit:

Found the problem (stupid one), but still program crashes after fixing it.

pPres should be type of Presentation, not Presentations (which is collection of Presentation).

The problem now is in this line in AutoWrap function (full code provided in link above)

// Make the call 
hr = pDisp->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT, 
    autoType, &dp, pvResult, NULL, NULL); 

After hitting that line I get unhandled exception and app breaks on LeaveCriticalSection in _unlock in mlock.c.

Was it helpful?

Solution

From the example you give us, you can not pass the wchar_t* string as an function parameter which you want to invoke in AutoWrap, you need package it as a BSTR type, which has a different memory layout that that of wchar_t* string, so it will cause crash.

The correct way is in the example you give us:

    VARIANT x; 
    x.vt = VT_BSTR; 
    x.bstrVal = SysAllocString(L"All-In-One Code Framework"); 
    AutoWrap(DISPATCH_PROPERTYPUT, NULL, pTxtRange, L"Text", 1, x); 
    VariantClear(&x); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top