在Embarcadero RAD Studio XE中使用Visual Studio DLL

Using Visual Studio DLL in Embarcadero RAD Studio XE?

本文关键字:Studio Visual DLL XE Embarcadero RAD      更新时间:2023-10-16

我打算在Embarcadero RAD Studio XE中的VCL Form C++项目中添加拼写检查器功能。

到目前为止,我已经成功地在Visual Studio 2012中创建了一个使用hunspell的应用程序,遵循了C++中的步骤-在Visual Studio 2010中使用hunspell 1.3.2。因此,我的第一个方法是重用在RADStudio中使用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"中得到了一个声明语法错误

代码片段:

// 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/)

好吧,如果有人试图在Embarcadero RAD Studio XE中使用hunspell,或者通常想知道如何使用由Visual Studio在Embarcandero RAD工作室XE中创建的DLL,我终于找到了解决方案。

命令行提示:

implib -a hunspell.lib hunspell.dll

创建一个可以添加到项目中的LIB文件。要查找函数原型,可以通过以下方式创建文本文件:

tdump -ee -m hunspell.dll > out.txt

最后,可以通过以下方式导入功能:

extern "C" __declspec(dllimport) [return type] [function name] ([function parameters]);

更多详细信息,请访问:https://labstreaminglayer.googlecode.com/hg-history/b51f278e31b7b276f20943b6bf2e1c1b5b964028/Apps/Embarcadero%20XE/Loading%20VS2008%20dlls%20into%20Embarcadero.txt