2016-08-15 91 views
1

我想了解如何使用Xerces-c-3.1.4 DLL。我下载了源代码并使用VS Studio Express 2015中的xerces-all.sln构建了DLL。未解决的外部'xercesc_3_1 :: XMLPlatformUtils :: Initialize'在C++ Builder测试应用程序

我已经写了一个非常简单的VCL应用程序(表单上的一个按钮)。这产生三种链接错误:

Unresolved external 'xercesc_3_1::XMLPlatformUtils::Terminate() 
Unresolved external 'xercesc_3_1::XMLUni::fgXercescDefaultLocale 
Unresolved external 'xercesc_3_1::XMLPlatformUtils::Initialize() 

发生在我身上可能的原因包括:

  • 我建立DLL时做错事
  • 我不需要.def文件处理与VC + +名称捣毁?尽管.sln中没有提供。
  • 我不需要为我使用的任何DLL函数调用GetProcAddress?但是我可以在哪里找到DLL中所有函数的模板?

下面是我的测试应用程序的代码:

#ifndef MainFrmH 
#define MainFrmH 

#include <System.Classes.hpp> 
#include <Vcl.Controls.hpp> 
#include <Vcl.StdCtrls.hpp> 
#include <Vcl.Forms.hpp> 
#include <xercesc/util/PlatformUtils.hpp> 
#include <xercesc/util/XMLString.hpp> 
#include <xercesc/dom/DOM.hpp> 
#include <xercesc/util/OutOfMemoryException.hpp> 

XERCES_CPP_NAMESPACE_USE 


class TMainForm : public TForm 
{ 
__published: // IDE-managed Components 
    TButton *InitButton; 
    void __fastcall InitButtonClick(TObject *Sender); 
private: // User declarations 
    HINSTANCE hXercesLib; 
public:  // User declarations 
    __fastcall TMainForm(TComponent* Owner); 
    __fastcall ~TMainForm(); 
}; 

extern PACKAGE TMainForm *MainForm; 

#endif 

#include <vcl.h> 
#include <iostream> 
#pragma hdrstop 

#include "MainFrm.h" 

#pragma package(smart_init) 
#pragma resource "*.dfm" 
TMainForm *MainForm; 

using namespace xercesc; 

__fastcall TMainForm::TMainForm(TComponent* Owner) 
    : TForm(Owner) 
{ 
    hXercesLib = NULL; 
} // ctor 

__fastcall TMainForm::~TMainForm() 
{ 
    if (hXercesLib) 
    { 
     XMLPlatformUtils::Terminate(); 
     FreeLibrary(hXercesLib); 
     hXercesLib = NULL; 
    } 
} // dtor 

void __fastcall TMainForm::InitButtonClick(TObject *Sender) 
{ 
    if (!hXercesLib) 
    { 
     hXercesLib = LoadLibrary("xerces-c_3_1.dll"); 
     try 
     { 
      XMLPlatformUtils::Initialize(); 

      ShowMessage("XMLPlatformUtils::Initialize succeeded"); 
     } 
     catch (Exception& e) 
     { 
      FreeLibrary(hXercesLib); 
      hXercesLib = NULL; 
      ShowMessage(e.Message); 
     } 
    } 
} 

回答

1

可以使用GetProcAddress()但它是你的代码设置更多的工作。您可以使用C++ Builder的命令行tdump.exe工具来获取DLL的导出函数名称的列表。

你可以或者使用C++ Builder的命令行implib.exe工具,带或不带a。 def文件,为该DLL创建静态导入.lib文件,然后将该文件添加到您的项目中。

+0

谢谢,雷米。它看起来好像解决方案使用了__cdecl调用约定而没有DEF文件。所以我运行impdef mydef.def xerces_c_3_1.dll,并收到“Warning ...:no exports”。很大的线索!我会继续挖掘和试验,并希望能够找到正确的版本。 – Kathleen

+0

对于任何未来可能会发现此线程的人来说,解决方案对我来说不是要对Xerces的构建指令进行假设。我做了他们推荐的“Borland”C++,使用我的Embarcadero CX10 Seattle编译器运行MAKE文件,并且它工作得很好。 – Kathleen