http://www.developer.com/net/cplus/article.php/3428561/Managed-Extensions-Using-the-Microsoft-Word-Spell-Checker-via-Automation.htm
Welcome to this week's installment of .NET Tips & Techniques! Each week, award-winning Architect and Lead Programmer Tom Archer demonstrates how to perform a practical .NET programming task using either C# or Managed C++ Extensions.
The following is a step-by-step demo of how to use Automation to access the Microsoft Word spell checker from a Managed C++ application. (The accompanying demo application allows you to quickly test these steps.)
To download the accompanying source code for this article, click here.
The founder of the Archer Consulting Group (ACG), Tom Archer has been the project lead on three award-winning applications and is a best-selling author of 10 programming books as well as countless magazine and online articles.
Managed Extensions: Using the Microsoft Word Spell Checker via Automation
October 29, 2004
using statement to the top of your form code:
using namespace Microsoft::Office::Interop;
Note: The class that you use to automate Microsoft Word is actually in the Microsoft::Office::Interop::Word namespace. However, that namespace includes an interface called System that will conflict with the .NET System namespace. As a result, I include the Microsoft::Office::Interop namespace and qualify the objects within that namespace with the Word namespace name (e.g., Word::ApplicationClass).
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
try
{
Word::ApplicationClass* winword = new Word::ApplicationClass();
Object* o = System::Reflection::Missing::Value;
bool success = winword->CheckSpelling(textBox1->Text, &o, &o, &o, &o, &o,&o, &o, &o, &o, &o, &o, &o);
System::Text::StringBuilder* str = new System::Text::StringBuilder();
str->AppendFormat(S"Your text has {0} errors", success == true ? S"NO" : S"spelling");
MessageBox::Show(str->ToString(), S"Spell Check Results");
}
catch(Exception* e)
{
MessageBox::Show(e->Message);
}
}
Note: The Word object's CheckSpelling method takes a large number of arguments. In order to indicate that you don't wish to pass values for those arguments, you can simply use the System::Reflection::Missing object.

Final Notes
The focus of this article was to illustrate how to use Automation from Managed C++. In that vain, I used one parameter of one method of the incredibly rich and robust Word object. To read more about the different parameters you can use with the CheckSpelling method (such as specifying a custom dictionary, ignoring case, etc.) and to view what else you can automate from the various Office products, refer to the MSDN Web site.
Download the Code
About the Author