我的目标是创建一个简单的 Win32 控制台应用程序,它使用 HunSpell 对用户输入的单词进行拼写检查。我尝试遵循适用于 Visual Studio 2008 和 HunSpell 1.2.1 的这个 codeproject 教程。
我不想使用提供的代码,因为我打算自己编写。此外,我想将 HunSpell 添加为 dll,而不是静态库。
以下是我采取的步骤:
- 创建了一个名为 myproject 的 Win32 控制台(空)项目。
- 从 SourceForge.org 下载 HunSpell 1.3.2。
- 将hunspell -1.3.2\src\hunspell和win_api 复制到myproject\myproject\HunSpell-Src
- 在解决方案中添加并转换了项目 libhunspell myproject\myproject\HunSpell-Src\win-api\libhunspell.vcproj 。
- 使我的调试版本在配置管理器中使用 debug_dll 和 libhunspell 的发布版本 release_dll。
- 重建libhunspell项目,在debug_dll和release_dll文件夹中分别生成了libhunspell.dll。
- 使我的控制台项目依赖于 libhunspell。(添加了对 libhunspell 的引用)
- 从 SourceForge.org 下载字典文件 en_US.aff 和 en_US.dic 到myproject\myproject\HunSpell-Dic 。
我不知道如何/在哪里添加代码项目教程中提到的处理器定义 HSPELLEDIT_DLL。
遵循MSDN上“在控制台应用程序中使用类库中的功能”下列出的步骤并没有改变结果。
我想用这样的程序测试它:
#include <iostream>
#include "HunSpell-Src/win_api/hunspelldll.h"
using namespace std;
void main()
{
void *spellObj = hunspell_initialize("HunSpell-Dic\\en_us.aff", "HunSpell-Dic\\en_us.dic");
char str[60];
cin >> str;
int result = hunspell_spell(spellObj, str);
if(result == 0)
cout << "Spelling error!";
else
cout << "Correct Spelling!";
hunspell_uninitialize(spellObject);
}
如果我尝试编译 VS 会产生以下错误消息:
myproject\myproject\hunspell-src\win_api\hunspelldll.h(34): fatal error C1083: Cannot open include file: 'hunspell.hxx': No such file or directory
Hunspell.hxx 存在于 myproject\myproject\HunSpell-Src\hunspell 中。IntelliSense 将#include "hunspell.hxx" 标记为错误,而选项卡没有聚焦并显示消息“错误:无法打开源文件 hunspell.hxx”,但在聚焦它之后,错误消失了。
感谢您的帮助。