Link to home
Start Free TrialLog in
Avatar of ch52jb
ch52jb

asked on

Spelling

I want to spell check individual words, just to find out if they are correctly spelt words, I'm not interested in spelling suggestions.  I don't want to spend any money on components, I currently have Word2000, and I need to do this from inside a COM object, so no form to host an ActiveX control.  What is the easiest way to do this?

Cheers
Avatar of yuxiliu
yuxiliu

I have office 97 installed, I think Off2000 is same.
if you are using MFC, follow this way:
classWizard -> add new class -> add by type lib -> browser -> office dir-> office -> MSWORD8.olb(you need check what is in off2000) -> "_Application".
at this point you get a wrapper class of word, you can use the method in this interface:

BOOL _Application::CheckSpelling(LPCTSTR Word, VARIANT* CustomDictionary, VARIANT* IgnoreUppercase, VARIANT* MainDictionary, VARIANT* CustomDictionary2, VARIANT* CustomDictionary3, VARIANT* CustomDictionary4, VARIANT* CustomDictionary5,
            VARIANT* CustomDictionary6, VARIANT* CustomDictionary7, VARIANT* CustomDictionary8, VARIANT* CustomDictionary9, VARIANT* CustomDictionary10)
{
      BOOL result;
      static BYTE parms[] =
            VTS_BSTR VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT;
      InvokeHelper(0x144, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms,
            Word, CustomDictionary, IgnoreUppercase, MainDictionary, CustomDictionary2, CustomDictionary3, CustomDictionary4, CustomDictionary5, CustomDictionary6, CustomDictionary7, CustomDictionary8, CustomDictionary9, CustomDictionary10);
      return result;
}


first param is the word you want check, "CustomDictionary" is the file of "*.dic" you can search in office directory. if word has error return FALSE otherwise return TRUE.

if you want use raw COM, by this way:

#import "...\MSWORD8.OLB" // you need check what's the type lib name is in off2000

IWordApplication* pWordApplication; // note: you need to check the IID of on your computer as you are using off2000
CoCreateInstance(CLSID_WordApplication, NULL, CLSCTX_ALL, IID_IWordApplication(void**) &pWordApplication); // get the interface point of word application.

if(pWordApplication->CheckSpelling(L"TestWord","CustomDic1", "CustomDic2"...))
{
//correct spelling
}
else
{
//wrong spelling
};
pWordApplication->Release();
ASKER CERTIFIED SOLUTION
Avatar of yuxiliu
yuxiliu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, CreateInstance should be:
CoCreateInstance(CLSID_WordApplication, NULL, CLSCTX_ALL, IID_IWordApplication,(void**) &pWordApplication);
Avatar of ch52jb

ASKER

I'f tried importing the type library, and I'm calling the create application function.  For any parameters I don't want, I'm using NULL.  However, I always get a return code of -858993460 no matter if the word is spelt right or wrong.  Any ideas why this is happening?
Avatar of ch52jb

ASKER

Answer accepted