CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2011
    Posts
    63

    spell checker throwing exception

    Hello,

    I'm trying to get the English dictionary object MS Word uses and I want to use it to spell check. Here is the code I'm writing to do that:

    Code:
    Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
    Microsoft.Office.Interop.Word.Dictionary EngDict = null;
    
    
    foreach (Microsoft.Office.Interop.Word.Language l in app.Languages)
    {
        if (l.Name.Contains("English (US)"))
        {
            EngDict = l.ActiveSpellingDictionary;
            break;
        }
    }
    
    EngDict.LanguageID = Microsoft.Office.Interop.Word.WdLanguageID.wdEnglishUS;
    object EngDictObj = EngDict;
    bool b = CheckSpelling("hello", EngDictObj);
    Here's the CheckSpelling function:

    Code:
    private bool CheckSpelling(string word, object dict)
    {
        Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
        object O = null;
    
        return app.CheckSpelling(word, ref O, ref O, ref dict, ref O, ref O, ref O, ref O, ref O, ref O, ref O, ref O, ref O);
    }
    The call to app.CheckSpelling(...) in my CheckSpelling function throws a COMException whose details say "Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT)". Can anyone see what I might be doing wrong?

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: spell checker throwing exception

    Don't create a new instance of your application object. Use the same one which generated the dictionary.
    If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.

    Yes; I have a blog too - http://the-angry-gorilla.com/

  3. #3
    Join Date
    Nov 2011
    Posts
    63

    Re: spell checker throwing exception

    Yes, that works! Thanks BigEd.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured