Spell check as an OS service


As Operating systems are maturing different features are finding its way into it. So much so that many software are totally becoming redundant as there USP is already a core OS feature.


Recently I needed to include some spell-checking in a software that I was writing. I used interop in MS Office (Word in particular) to get this done. Since spell checking is so widely used I do think they should now become part of Windows. It’d be great if the context menu of text boxes have some think like “Check spelling” along with Cut/Copy/Paste.


The issue is not that things like spell checking is hard to do. The issue is including new dependencies. Now I have a 30 line code that uses Word for spell checking but can I rely on MS Word being installed on all machines where the software will be deployed? This is where OS support comes into play. Someone even suggested using Web-services to get this done!!! That is simply not feasible both from perf as well as security reasons…


The code I used goes as follows….

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop.Word;
using System.Reflection;
namespace SomeNameSpace
{
class SpellCheck : IDisposable
{
private ApplicationClass m_winword;
public SpellCheck()
{
m_winword =
new ApplicationClass();
}
public void Dispose()
{
object savenochanges = WdSaveOptions.wdDoNotSaveChanges;
object nothing = Missing.Value;
if (m_winword != null)
m_winword.Quit(
ref savenochanges, ref nothing,
ref nothing);
m_winword =
null;
}
public bool IsCorrect(string word)
{
object nothing = Missing.Value;
return m_winword.CheckSpelling(word,
ref nothing, ref nothing,
ref nothing, ref nothing,
ref nothing, ref nothing,
ref nothing, ref nothing,
ref nothing, ref nothing,
ref nothing, ref nothing);
}
}
}


This can be used as in

SpellCheck spellCheck = new SpellCheck();

if(!spellCheck.IsCorrect(someWord))
// not correct message

Comments (6)

  1. Maxim Moiseev says:

    Great idea, really!

    But! Maybe being a part of some framework is better choice? I mean .Net framework surely.

    IMHO, in the case of OS service spell checking would be platform dependent.

  2. Boris Sevo says:

    When I run this example I receive this error:

    "Cannot find proofing tools for Croatian. If you have the proofing tools, try installing or re-installing them.nContact your local reseller to obtain Office Proofing Tools. For more information, see the Microsoft Office Site

    ."

    I am from Croatia and when I try this:

    int i = winwrd.LanguageSettings.get_LanguageID(Microsoft.Office.Core.MsoAppLanguageID.msoLanguageIDInstall);

    ("i" is set to 1050 (language ID for Croatia))

    i = winwrd.LanguageSettings.get_LanguageID(Microsoft.Office.Core.MsoAppLanguageID.msoLanguageIDExeMode);

    ("i" is set to 0 (language ID for English))

    I suppose I can solve this problem if I reinstall the Word, but Is there any other way to solve this problem?

  3. abhinaba says:

    You need not reinstall Word but you do need to to install the language support.

  4. Boris Sevo says:

    I know that I need additional tools for Croatian, but I want to be able to make English spell-check. On my computer, example is always trying to make Croatian spell-check (probably because it is install language in Word). If I switch default language in Word from Croatian to English, I am then able to make english spell-check in Word but I am still not able to make that in your example.

  5. Eli Montague says:

    ok… the way you are doing this it using the spell check of MS Word as a OS level spell check? So dose it work just like the real time spell check in Word? and can it be used with Open Office’s Writer or MS Word Proceser in sted of MS Word? I don’t know how to use c# to write a base line for a program. I really don’t know how to use c# or c++ at all… why don’t you post the in an .EXE file instead of line code?

    Is you e-mail me at l_eli_montague@yahoo.ie  and tell me how I may/can use the line code to write a program. I know you can use the macro function in Word to write programs but I don’t know just how it works….

    P.S. Nice reference to 42 and the guide …

  6. swap says:

    I want to place comboBox

    so user can select language for spell check

    Plz help !!!!!