Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

INFO: Type Libraries for Office May Change with New Release


View products that this article applies to.

This article was previously published under Q224925

↑ Back to the top


Summary

Microsoft Office products may change from one release to the next. Typically, the type library for an Office product will have the same functions that were present in the earlier product version, but some functions may have additions to the number of arguments. Therefore, if you use ClassWizard-generated wrapper classes for an Office object library with code written against an early version of the object library, you might receive the following compilation error:
error C2660: '(function)' : function does not take (n) parameters

↑ Back to the top


More information

To illustrate, one such function that has changed is the Microsoft Word 2000 Add method of the Documents object. If you've used the ClassWizard to generate class wrappers for the functions in the Microsoft Word 2000 type library and you use code that worked with Microsoft Word 97, you will receive the compile error previously described. The following describes how you can correct this problem. Note that although the case illustrated applies to code that specifically automates Word, the same information can be applied to the other Microsoft Office applications.

With the Word 97 type library, you could use the following code to automate Word and start a new document:
   _Application oApp;
   Documents oDocs;
   _Document oDoc;
   COleVariant vtOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR),
               vtTrue((short)TRUE),
               vtFalse((short)FALSE);

   // Create an instance of Word
   if (!oApp.CreateDispatch("Word.Application")) 
   {
      AfxMessageBox("Word failed to start!");
      return;
   } 
	
   // Add a new document and make Word visible
   oDocs = oApp.GetDocuments();
   oDoc = oDocs.Add(vtOptional,vtOptional);
   oApp.SetVisible(TRUE);
				
If you attempt to run this code against the Word 2000 type library, you will receive the compile error C2660 "'Add' : function does not take 2 parameters" for the following line of code:
     oDoc = oDocs.Add(vtOptional,vtOptional);
				
To correct this problem, you can perform the following steps.
  1. Go to the ClassView tab of the Project Workspace window.
  2. In the Classes list for your workspace, double-click the Documents class to display its members.
  3. Locate the Add Member function and you will see that it is expecting four arguments. Your code is only passing two arguments, thus you receive the compile error.
  4. Refer to the Visual Basic Help in Microsoft Word and locate the topic for the Add Method of the Documents object to determine what type of data to use for these arguments and/or to determine if the arguments are optional. In this case, both new arguments are optional.
  5. Return to your project and modify the offending line of code to read:
       oDoc = Docs.Add(vtOptional,vtOptional,vtOptional,vtOptional);
    					
  6. Recompile the project. It should now compile without the error.

Automating Multiple Versions of Office Applications

If you intend to write MFC code that will automate multiple versions of a Microsoft Office application, you should use the ClassWizard to generate wrapper classes from the type library of the earliest version. For example, if you would like your Automation client to support both Microsoft Word 97 and 2000, use the Word 97 type library for your wrapper classes. Likewise, if you want your Automation client to support both Microsoft 2000 and 2002, use the Word 2000 type Library for your wrapper classes.

↑ Back to the top


References

For more information on Office Automation, please visit the Microsoft Office Development support site at:

↑ Back to the top


Keywords: KB224925, kbinfo, kbautomation

↑ Back to the top

Article Info
Article ID : 224925
Revision : 9
Created on : 1/24/2007
Published on : 1/24/2007
Exists online : False
Views : 603