COMEXCEL Sample: Demonstrates an Automation Client Application with Compiler COM Support

COMEXCEL is a standalone Automation client. It creates a new Microsoft Excel spreadsheet and generates a pie chart of the data stored on that spreadsheet. This sample works only with Microsoft Excel, which exposes the dispinterfaces.

Security noteSecurity Note

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To get samples and instructions for installing them:

To access samples from Visual Studio

  • On the Help menu, click Samples.

    By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.

  • For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.

Building and Running the Sample

Make sure that the #import reference to COMEXCEL.exe in the sample's source code is correct for your computer.

To build this sample within Visual C++, determine which version of Excel you have on your computer and then look in the appropriate COMEXCEL sample directory.

To build and run this sample

  1. Open the solution comexcel.sln.

  2. If you are using Excel 2000, modify the following line in comexcel.cpp:

    #define OFFICE_VER OFFICEXP
    

    to instead be:

    #define OFFICE_VER OFFICE2000
    
  3. On the Build menu, click Build Solution.

  4. On the Debug menu, click Start Without Debugging.

Keywords

This sample demonstrates the following keywords:

dispinterface; #import; _com_ptr_t; _variant_t; _bstr_t; _com_error

See Also

Reference

Compiler COM Support

Other Resources

Compiler COM Support Samples

General Samples