Click here to Skip to main content
Email Password   helpLost your password?

Introduction

Searching around in MSDN trying to find how to use the MS Office spell checker, I found a "fantastic" OLE solution:

  1. Run Word
  2. Push the word to be checked into Word
  3. Get the result.

Thanks very much :(

Then I found this. Through them, I got the Microsoft Common Spell API (CSAPI).

CSAPI

To ensure I respect copyright, I cut the smallest possible example using the default dictionary only, and ignored possible error states or exceptions. You will probably need to modify it for your language and paths (I'm not reading paths from registry).

Below is some sample code that illustrates how to use the SDK.

#include "windows.h"

#include "csapi.h" //with typedef unsigned char CHAR; removed


typedef WORD (*SpellInit_fn) (SPLID FAR *lpSid,
                              WSC FAR  *lpWsc);

typedef WORD (*SpellOpenMdr_fn)(SPLID    splid,
                                LPSPATH  lpspathMain,
                                LPSPATH  lpspathExc,
                                BOOL     fCreateUdrExc,
                                BOOL     fCache,
                                LID      lidExpected,
                                LPMDRS   lpMdrs);

typedef WORD (*SpellCheck_fn)(SPLID    splid,
                              SCCC     iScc,
                              LPSIB    lpSib,
                              LPSRB    lpSrb);

typedef WORD (*SpellCloseMdr_fn)(SPLID    splid,
                                 LPMDRS   lpMdrs);

typedef WORD (*SpellTerminate_fn)(SPLID    splid,
                                  BOOL     fForce);

void main(void)
{
    int Language = 1051; //slovak


    //to be more general search thru registry:

    //Dll functional interface:

    //  HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\

    //           Proofing Tools\Spelling\1051\Normal\Engine

    //Mdr main directory:

    //  HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\

    //           Proofing Tools\Spelling\1051\Normal\Dictionary

    //Under any user directory:

    //  HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\

    //           Proofing Tools\Custom Dictionaries\1


    char DllName[] = 
     "C:\\Program Files\\Common Files\\Microsoft Shared\\Proof\\MSPSK32.DLL";
    char MdrName[] = 
     "C:\\Program Files\\Common Files\\Microsoft Shared\\Proof\\MSSP_SK.LEX";

    HMODULE SpellInstance = LoadLibrary(DllName);

    SpellInit_fn SpellInit = 
      (SpellInit_fn)GetProcAddress(SpellInstance, 
      "SpellInit");
    SpellOpenMdr_fn SpellOpenMdr = 
      (SpellOpenMdr_fn)GetProcAddress(SpellInstance, 
      "SpellOpenMdr");
    SpellCheck_fn SpellCheck = 
      (SpellCheck_fn)GetProcAddress(SpellInstance, 
      "SpellCheck");
    SpellCloseMdr_fn SpellCloseMdr = 
      (SpellCloseMdr_fn)GetProcAddress(SpellInstance, 
      "SpellCloseMdr");
    SpellTerminate_fn SpellTerminate = 
      (SpellTerminate_fn)GetProcAddress(SpellInstance, 
      "SpellTerminate");

    SPLID Handle;
    WSC SpecChars;
    SpecChars.bIgnore = 0;
    SpecChars.bHyphenHard = 45;
    SpecChars.bHyphenSoft = 31;
    SpecChars.bHyphenNonBreaking = 30;
    SpecChars.bEmDash = 151;
    SpecChars.bEnDash = 150;
    SpecChars.bEllipsis = 133;
    SpecChars.rgLineBreak[0] = 11;
    SpecChars.rgLineBreak[1] = 10;
    SpecChars.rgParaBreak[0] = 13;
    SpecChars.rgParaBreak[1] = 10;

    SpellInit(&Handle, &SpecChars);

    MDRS Mdrs;
    SpellOpenMdr(Handle, MdrName, NULL, FALSE, TRUE, Language, &Mdrs);

    SIB InputBuffer;
    InputBuffer.cMdr = 1;
    InputBuffer.lrgMdr = &Mdrs.mdr;
    InputBuffer.cUdr = 0;
    InputBuffer.lrgUdr = NULL;

    SRB ResultBuffer;
    ResultBuffer.cch = 1024;
    ResultBuffer.lrgsz = (char*)malloc(ResultBuffer.cch);
    ResultBuffer.cbRate = 255;
    ResultBuffer.lrgbRating = (unsigned char*)malloc(ResultBuffer.cbRate);

    InputBuffer.lrgch = "slovo"; //tested word

    InputBuffer.cch = strlen(InputBuffer.lrgch);
    InputBuffer.wSpellState = fssStartsSentence;
    SpellCheck(Handle, sccVerifyWord, &InputBuffer, &ResultBuffer);

    int Result = ResultBuffer.scrs; //scrsNoErrors


    free(ResultBuffer.lrgsz);
    free(ResultBuffer.lrgbRating);
    SpellCloseMdr(Handle, &Mdrs);
    SpellTerminate(Handle, TRUE);
    FreeLibrary(SpellInstance);
}

I have tried the above code with Office 95 and Office 97. Installing Office 2000 with English, Slovak and German languages creates a registry Spelling\1051 (slovak) and Grammar\1031 (german) entries.

BTW: My search for a similar WIN API for string comparison failed. It seems Windows knows how to use the actual language only (resp. see .NET Framework Reference, String.Compare Method (String, String, Boolean, CultureInfo)), and there is no way to hook between your application and the system to correct the MS bugs for "small markets" like my country (where exceptional vocabulary or similar solution are necessary for proper string evaluation). If you know more about this, do not hesitate to publish it.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralCSAPI3
leebauer
1:55 2 Nov '09  
any body have CSAPI3 api plees
Generalhow to complile
leebauer
7:21 21 Oct '09  
please tell me how to compile using vc6 or attach the all project with .dsw
GeneralRe: how to complile
Tibor Blazko
1:04 25 Oct '09  
please have a look at attached makefile to see dependencies
(unfortunately i have no acces to vs now, anyway article is already very old)
Generalcreating local language spell cheking
tedkidane
8:39 1 Oct '09  
please tell me how to create new and local language spell checking tool that means how to create custom lex and dll for new language

tewodros

GeneralRe: creating local language spell cheking
Tibor Blazko
10:21 1 Oct '09  
i'm. sorry, too long time from article was written
please search msdn and ask in codeproject forums
GeneralUsing unicode chars
mita55555
2:34 26 Aug '09  
How about unicode?
GeneralRe: Using unicode chars
Tibor Blazko
2:39 26 Aug '09  
i'm. sorry, too long time from article was written
(last time i read something about spellchecking it was related to wpf TextBox)
GeneralWhat are the license terms
Dwayne Bailey
8:14 28 Jan '07  
I'm investigating reverse engineering CSAPI to work with Enchant and thus a number of Open Source spell checkers.

In the CSAPI listed on this site it says...

THE SOURCE FILES ASSOCIATED WITH THE CSAPI SPECIFICATION ARE SUBJECT TO THE
TERMS OF THE CSAPI LICENSE AGREEMENT INCLUDED IN THE SPECIFICATIONS,
COMMON SPELLER APPLICATION PROGRAMMING INTERFACE (CSAPI) SECTION OF THE
DEVELOPMENT LIBRARY. BY INSTALLING AND USING THESE SOURCE FILES, YOU
INDICATE YOUR ACCEPTANCE OF THIS LICENSE AGREEMENT.

Does anyone have a copy of the CSAPI license agreement? Better yet does anyone have a copy of the old MSDN that included the CSAPI 1 spec? And do they know under what terms that was made available.
GeneralProblem Creating a New Dictionary for MS Office Sort by Position Word List
mfcuser
7:45 31 Aug '04  
I do have all the resources necessary to create a new dictionary for another language that is no English. I receive a program from Microsoft to compile the list of words that I have. Everything works fine, except I have one problem. The language I want to create the dictionary for is an accented language. Microsoft provides me with a utility where I have to sort my list before create the main dictionary. I can create the main dictionary by running the utility in the command line plus my list. In order for the utility to compile my list, the list has to be sorted. Since the language in question contains words with accents and apostrophes, I have to sort the list by position. When I use a small list without accent and apostrophes, the program compiles my list without problem. I try to sort the whole list in Word, but it doesn’t work, because Word cannot sort by position. My problem now is to sort the whole list by position. I don’t want to write a program for that, because it will take more time. I wonder if there is a utility I can use or any other program to sort the list by position. I will appreciate your help or suggestion. I ask Microsoft if they have a utility that can help me to sort the list by position; they told me they don’t have one.
GeneralRe: Problem Creating a New Dictionary for MS Office Sort by Position Word List
Shaheer Ahmad
23:23 7 Dec '04  
HI,

I want to work with MS Word for my native language.I have list of word in text format. I want to compile this word list compatiabile for MS Word.You told this group that You have compile the list of word and create main dictionary.I also want same thing.Will u pls tell me from where u got source code which one used for create main dictionary. if u have source code then pls send me.

Thanks & regards
Shaheer Ahmad
ahmad.shaheer@netsity.com
mobile:+91-9868311169



Shaheer Ahmad
ahmad.shaheer@netsity.com
mobile:+91-9868311169


GeneralRe: Problem Creating a New Dictionary for MS Office Sort by Position Word List
mfcuser
3:48 8 Dec '04  
It is a little bit complicated. First you have to get the compiler and the license from microsoft. It involves signing some paper work as well. After that, you have to a lot of tricks. For example, I wrote my own sorting function to sort the list then created the binary file. Now, the problem I have is to create the .lex file. I haven't had enough time to work on the finale step which is creating the .lex file. The last time I tried it, it did not work. I have conctacted microsoft, they haven't responded to me. Keep in mind they don't provide any support for the process.
GeneralRe: Problem Creating a New Dictionary for MS Office Sort by Position Word List
Shaheer Ahmad
4:56 8 Dec '04  
Dear friend

I really appreciate your such a quick response. Thanks for the same.

Could you let me know the contact details at Microsoft or the process to
sign up the license agreement with them to get the compiler? As
suggested by you this seems to be the first step to move in this
direction. I understand there would be bottlenecks ahead but lets start
it from here Smile .

Looking forward to your response.

Thanks & Regards
Shaheer Ahmad

GeneralRe: Problem Creating a New Dictionary for MS Office Sort by Position Word List
mlavaud2005
23:21 12 May '05  
Hello mfcuser and Shaheer Ahmad,

I have the same need: create a Word lexicon. Would you send me info about the contact at Microsoft so I can get a license for the compiler ?

My email address: marc_lavaud@hotmail.com

Thank you very much
Marc Lavaud
EOA European Occitan Academia

GeneralRe: Problem Creating a New Dictionary for MS Office Sort by Position Word List
mertart
23:18 14 May '05  
Hi all!
Now I'm working on spell checker for my native language.
Can you sand me information about that MS license and compiler?

My email address: mertart@mail.ru

It's VERY important for me!
Thank you.
GeneralRe: Problem Creating a New Dictionary for MS Office Sort by Position Word List
RakeshShivanna
21:50 5 Jun '06  
Hello

I have the same need: create a Word lexicon. And Read the Microsoft Lexicon file i.e, .lex

My email address: rakeshs@focussoftek.com



Rakesh S
GeneralProblem running the code...
deepblue1
4:44 29 May '04  
Hello, I m facing some problem in running the supplied demo code. I have used VC 6.0. I opened the SP.DSW using "Open Workspace". When I try to run the file, I get following errors:

C:\Downloads\SpellChecker\CodeProj\sp\spell.c(387) : error C2065: 'READ' : undeclared identifier
C:\Downloads\SpellChecker\CodeProj\sp\spell.c(741) : error C2065: 'WRITE' : undeclared identifier

sp.exe - 2 error(s), 0 warning(s)

I m not an expert in VC, so maybe i m doing a stupid mistake. Please help. Thanks
GeneralRe: Problem running the code...
Tibor Blazko
20:59 6 Jun '04  
sorry (for old example)
please use OF_READ and OF_WRITE insted of them (see _lopen msdn entry)
GeneralRe: Problem running the code...
alfonso.gonzalez
6:55 14 Jul '05  
I had this problem before. I changed READ for OF_READ and WRITE for OF_WRITE and now muy problem is this message: "could not load spell module spell.dll" Would you like to help me?

Sorry for my English.
GeneralRe: Problem running the code...
Tibor Blazko
6:59 15 Jul '05  
i'm very sorry will not help you in nearest time (article was made on old office version, should be something changed from that time - see article discussion)

generaly please try to search in program files/common files/microsoft shared for *.dll with "spell" or "sp" inside file name (should vary with language), maybe search for any known function name inside

or have a look to f.e. openoffice.org (if their license fits to you ...), just it is already theme for new article of another author
GeneralCSAPI 3 Dcoumentation
schler
1:49 6 Jan '03  
Hi,
I noticed that the API in CSAPI3 has changed from the version published here. Does anyone have the updated API reference

Thanks

Jonathan
GeneralCSAPI for Office 2000 and XP?
Anonymous
9:10 19 Apr '02  
Does anybody have information about how to implement calls to the new MS Office spell check dll's? The path is not stored in the registry anymore and the commands are not similar to Office 95/97 CSAPI

Thank you
GeneralRe: CSAPI for Office 2000 and XP?
Tibor Blazko
2:39 7 May '02  
(sorry for delay, i'm not notified about anonymous comments)
having no possibility to test it but i see w2002 mention into article's ms link
(if you are right than try look at mentioned ole solution http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnoffdev/html/vsofficedev.asp resp. "VARIANT in MSWORD spell check" at http://www.codeguru.com/forum/showthread.php?s=&threadid=158892&highlight=%2ACheckSpelling%2A)
t!
GeneralRe: CSAPI for Office 2000 and XP?
Luzius Schneider
4:49 15 May '02  
Unfortunately, the vc ole discussion article mentions only using MSWord automation for spell checking. It does not use the spell check engine (dll) directly. This is much to much overhead!
The CSAPI information above allows to use the dll directly (Word not required). Unfortunately, this works only for MSOffice 95/97 and for some few languages with MSOffice 2000.

Generalspell checking problem
Anonymous
2:22 13 Mar '02  
Hi !

I'm trying to add spell checking functionality to my application using the 'Common Speller Application Programming Interface (CSAPI)'.
The problem is that I can not add any word to the user dictionary, I get always the error code 1 (secOOM).

I use the SpellOpenUdr function In order to open the custom dictionary :
if (SpellOpenUdr(sid, UdrName, TRUE, IgnoreAlwaysProp, (UDR FAR *)&udr, (BOOL FAR *)&fUdrRO) != 0)
{
//…
}

The function used to add a word into the dictionary is SpellAddUdr :
if ((sec = SpellAddUdr(sid, udr, vlpszSpellError) != 0))
{
//...
}

Does anybody know what means the secOOM error code ?

Many thanks,
Vasile

GeneralRe: spell checking problem
real name
4:14 13 Mar '02  
i expect out-of-memory problem
t!


Last Updated 15 Jun 2001 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010