I have been playing some more with the library and received some mixed results. The following code starts a session with a new dictionary and associated file as described in
hunspell(4) - Linux man page[
^] (see also
hunspell(3) - Linux man page[
^] and
hunspell(1) - Linux man page[
^]). It is difficult to know when the ADD function succeeds, as the results of a spell check are not consistent. I suspect more information is needed but this could be a start. This code was thrown together rather but shows the two basic functions. One important point to note, which I missed yesterday, is the requirement for a HANDLE returned from the
Hunspell_create
function, which must be past in on all the following calls.
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
HMODULE hHunspellLib = NULL;
HANDLE hHunspellHandle = NULL;
bool HunspellInit(const char* aff, const char* dic) {
bool result = false;
hHunspellLib = ::LoadLibrary("Hunspellx64");
if (hHunspellLib == NULL)
{
DWORD dw = GetLastError();
cout << "LoadLibrary failed, error code: " << hex << dw << dec << endl;
}
else
{
typedef HANDLE (*HunspellCreateFunc)(const char*, const char*);
HunspellCreateFunc Hunspell_create = (HunspellCreateFunc)GetProcAddress(hHunspellLib, "Hunspell_create");
if (Hunspell_create == NULL) {
cout << "GetProcAddress failed for \"Hunspell_create\"" << endl;
}
else
{
hHunspellHandle = Hunspell_create(aff, dic);
result = true;
}
}
return result;
}
int HunspellAddWord(const char* Word2Add)
{
typedef int(*HunspellAddWordFunc)(HANDLE, const char*);
static HunspellAddWordFunc Hunspell_add = nullptr;
int result = 0;
if (Hunspell_add == nullptr)
{
Hunspell_add = (HunspellAddWordFunc)GetProcAddress(hHunspellLib, "Hunspell_add");
if (Hunspell_add == nullptr) {
cout << "GetProcAddress failed for\n\nHunspell_add" << endl;
return result;
}
}
else
{
result = Hunspell_add(hHunspellHandle, Word2Add);
}
return result;
}
int HunspellSpellWord(const char* Word2Spell)
{
typedef int(*HunspellSpellWordFunc)(HANDLE, const char*);
static HunspellSpellWordFunc Hunspell_spell = nullptr;
int result = 0;
if (Hunspell_spell == nullptr)
{
Hunspell_spell = (HunspellSpellWordFunc)GetProcAddress(hHunspellLib, "Hunspell_spell");
if (Hunspell_spell == nullptr) {
cout << "GetProcAddress failed for\n\nHunspell_spell" << endl;
return result;
}
}
else
{
result = Hunspell_spell(hHunspellHandle, Word2Spell);
}
return result;
}
int main()
{
if (!HunspellInit("spelltest.aff", "spelltest.dic"))
{
return 1;
}
string input;
while (true)
{
cout << "enter a word: ";
cin >> input;
if (input == "END")
break;
if (input == "ADD")
{
cout << "enter the word to add: ";
cin >> input;
int addresult = HunspellAddWord(input.c_str());
cout << "add returned: " << addresult << endl;
}
else
{
int gorb = HunspellSpellWord(input.c_str());
cout << (gorb == 1 ? "Correct" : "Wrong") << endl;
}
}
return 0;
}
1. Affix file
SET UTF-8
TRY esianrtolcdugmphbyfvkwzESIANRTOLCDUGMPHBYFVKWZ'
REP 2
REP f ph
REP ph f
Dictionary file
5
mouse
handle
door
*pickle
tribulation