在Embarcadero RAD Studio XE中使用Visual Studio DLL吗? [英] Using Visual Studio DLL in Embarcadero RAD Studio XE?
问题描述
我打算在Embarcadero RAD Studio XE的VCL Form C ++项目中添加拼写检查器功能.
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.
我的第二种方法是导入hunspell源代码并包含"hunspell.hxx".但是我在文件"csuitl.hxx"中得到了声明语法错误
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"
代码段:
// 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包含到我的项目中的简单方法,因为它是一种广泛使用的工具.任何帮助表示赞赏:)
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文档: http://sourceforge.net/projects/hunspell/文件/Hunspell/文档/)
(hunspell documentation: http://sourceforge.net/projects/hunspell/files/Hunspell/Documentation/)
推荐答案
好吧,如果有人尝试在Embarcadero RAD Studio XE中使用hunspell,或者通常想知道如何使用Embarcadero内部由Visual Studio创建的DLLRAD Studio XE,我终于找到了解决方案.
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.
命令行提示符:
implib -a hunspell.lib hunspell.dll
创建一个LIB文件,该文件可以添加到项目中.要查找功能原型,可以通过以下方式创建文本文件:
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]);
您可以在以下位置找到更多详细信息: https://lab.googlecode.com/hg-history/b51f278e31b7b276f20943b6bf2e1c1b5b964028/Apps/Embarcadero%20XE/Loading%20VS2008%20dlls%20into%20Embarcadero.txt
You can find more details at: https://labstreaminglayer.googlecode.com/hg-history/b51f278e31b7b276f20943b6bf2e1c1b5b964028/Apps/Embarcadero%20XE/Loading%20VS2008%20dlls%20into%20Embarcadero.txt
这篇关于在Embarcadero RAD Studio XE中使用Visual Studio DLL吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!