Homepage image
image RSS Feed

Sample Download : http://code.msdn.microsoft.com/CppAutomatePowerPoint-714e1481

The CppAutomatePowerPoint example demonstrates how to write VC++ code to create a Microsoft PowerPoint instance, create a new presentation, insert a new slide, add some texts to the slide, save the presentation, quit PowerPoint and then clean up unmanaged COM resources.

There are three basic ways you can write VC++ automation codes:

1. Automating PowerPoint using the #import directive and smart pointers

The code in Solution1.h/cpp demonstrates the use of #import to automate PowerPoint. #import (http://msdn.microsoft.com/en-us/library/8etzzkb6.aspx), a new directive that became available with Visual C++ 5.0, creates VC++ "smart pointers" from a specified type library. It is very powerful, but often not recommended because of reference-counting problems that typically occur when

used with the Microsoft Office applications. Unlike the direct API approach in Solution2.h/cpp, smart pointers enable us to benefit from the type info to early/late bind the object. #import takes care of adding the messy guids to the project and the COM APIs are encapsulated in custom classes that the #import directive generates.

2. Automating PowerPoint using C++ and the COM APIs

The code in Solution2.h/cpp demontrates the use of C/C++ and the COM APIs to automate PowerPoint. The raw automation is much more difficult, but it is sometimes necessary to avoid the overhead with MFC, or problems with #import. Basically, you work with such APIs as CoCreateInstance(), and COM interfaces such as IDispatch and IUnknown.

3. Automating PowerPoint with MFC

With MFC, Visual C++ Class Wizard can generate "wrapper classes" from the type libraries. These classes simplify the use of the COM servers. Automating PowerPoint with MFC is not covered in this sample.

image

 

 

imageYou can find more code samples that demonstrate the most typical programming scenarios by using Microsoft All-In-One Code Framework Sample Browser or Sample Browser Visual Studio extension. They give you the flexibility to search samples, download samples on demand, manage the downloaded samples in a centralized place, and automatically be notified about sample updates. If it is the first time that you hear about Microsoft All-In-One Code Framework, please watch the introduction video on Microsoft Showcase, or read the introduction on our homepage http://1code.codeplex.com/.