【问题标题】:Using Visual Studio DLL in Embarcadero RAD Studio XE?在 Embarcadero RAD Studio XE 中使用 Visual Studio DLL?
【发布时间】: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


    【解决方案1】:

    好吧,如果有人尝试在 Embarcadero RAD Studio XE 中使用 hunspell,或者想知道如何使用由 Visual Studio 在 Embarcadero RAD Studio 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

    【讨论】:

    • 你好@Andreas 你能告诉我这个 tdump 命令是什么吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 2016-12-25
    • 1970-01-01
    相关资源
    最近更新 更多