【发布时间】:2016-01-29 21:19:49
【问题描述】:
我打算在 Embarcadero RAD Studio XE 的 VCL Form C++ 项目中添加拼写检查功能。
到目前为止,我按照C++ - Using HunSpell 1.3.2 with Visual Studio 2010 中的步骤成功地在Visual Studio 2012 中创建了一个使用hunspell 的应用程序。因此,我的第一个方法是重用在 RAD Studio 中使用 VS 编译器创建的 .dll。
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
// dll path
const wchar_t* library = L"libhunspell.dll";
// hunspell constructor
extern "C" __declspec(dllimport) hunspell_initialize(char const * aff,char const * dic);
//adds a word to the loaded dictionary
extern "C" __declspec(dllimport) int add(char const *) ;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
HINSTANCE load;
try
{ load = LoadLibrary(library); }
catch(Exception &e)
{ ShowMessage(e.Message); }
if (load)
{
ShowMessage("Library Loaded!");
hunspell_initialize("de_DE.aff","de_DE.dic");
add("myword");
}
else {ShowMessage ("Library hasn't loaded!");}
}
我可以加载库,但是链接器无法解析外部函数。
我的第二种方法是导入 hunspell 源代码并包含“hunspell.hxx”。但是我在文件“csuitl.hxx”中得到一个声明语法错误
代码sn-p:
// default flags
#define DEFAULTFLAGS 65510
#define FORBIDDENWORD 65510
#define ONLYUPCASEFLAG 65511
// fopen or optional _wfopen to fix long pathname problem of WIN32
LIBHUNSPELL_DLL_EXPORTED FILE * myfopen(const char * path, const char * mode); // << error line
// convert UTF-16 characters to UTF-8
LIBHUNSPELL_DLL_EXPORTED char * u16_u8(char * dest, int size, const w_char * src, int srclen);
// convert UTF-8 characters to UTF-16
LIBHUNSPELL_DLL_EXPORTED int u8_u16(w_char * dest, int size, const char * src);
我想知道,我是否缺少一种将 hunspell 包含到我的项目中的简单方法,因为它是一种广泛使用的工具。任何帮助表示赞赏:)
(hunspell 文档:http://sourceforge.net/projects/hunspell/files/Hunspell/Documentation/)
【问题讨论】:
标签: c++ visual-studio c++builder dllimport hunspell