I'm intending to add a spellchecker feature into a VCL Form C++ project in Embarcadero RAD Studio XE.
So far, I succeeded in creating an application that uses hunspell in Visual Studio 2012 following the steps in C++ - Using HunSpell 1.3.2 with Visual Studio 2010. Therefore my first approach was to reuse the .dll created with the VS compiler in RAD Studio.
#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!");}
}
I can load the library, however the linker is unable to resolve the external functions.
My second approach was to import the hunspell source code and include "hunspell.hxx". However I get a declaration syntax error in the file "csuitl.hxx"
code snippet:
// 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);
I'm wondering, if I'm missing a simple way to include hunspell into my project since it's a widely used tool. Any help is appreciated :)
(hunspell documentation: http://sourceforge.net/projects/hunspell/files/Hunspell/Documentation/)
Well, if anyone ever tries to use hunspell in Embarcadero RAD Studio XE, or generally wants to know how to use a DLL that was created by Visual Studio inside Embarcadero RAD Studio XE, I finally found a solution.
The command line prompt:
implib -a hunspell.lib hunspell.dll
creates a LIB file which can be added to the project. To look up function prototypes, you can create a text file by:
tdump -ee -m hunspell.dll > out.txt
Finally, functions can be imported by:
extern "C" __declspec(dllimport) [return type] [function name] ([function parameters]);
You can find more details at: https://labstreaminglayer.googlecode.com/hg-history/b51f278e31b7b276f20943b6bf2e1c1b5b964028/Apps/Embarcadero%20XE/Loading%20VS2008%20dlls%20into%20Embarcadero.txt