导入Embarcadero C++;将XE3 DLL构建到Embarcadero C++;生成器XE3

导入Embarcadero C++;将XE3 DLL构建到Embarcadero C++;生成器XE3,dll,c++builder,stdcall,c++builder-xe,getprocaddress,Dll,C++builder,Stdcall,C++builder Xe,Getprocaddress,我尝试在AcjCabror C++ +Builder XE3中创建一个DLL,并将它应用于同一环境中的一个测试项目。 我举了一个教程的例子,该教程的代码对我来说并没有很好的结果(!): 以下是我的DLL的内容: BaseAuth.h文件: #ifndef BaseAuthH #define BaseAuthH #include <System.hpp> class TBaseAuth { public: virtual void TestMessage() = 0;

我尝试在AcjCabror C++ +Builder XE3中创建一个DLL,并将它应用于同一环境中的一个测试项目。 我举了一个教程的例子,该教程的代码对我来说并没有很好的结果(!):

以下是我的DLL的内容:

BaseAuth.h文件:

#ifndef   BaseAuthH
#define   BaseAuthH

#include <System.hpp>
class TBaseAuth
{
public:
    virtual void TestMessage() = 0;
};
#endif // BaseAuthH
//---------------------------------------------------------------------------
#ifndef AuthH
#define AuthH
//---------------------------------------------------------------------------
#include "BaseAuth.h"
class TAuth : public TBaseAuth
{
public:
    TAuth();
    ~TAuth();   
    void TestMessage();
};
#endif
Auth.cpp文件:

//---------------------------------------------------------------------------
#pragma hdrstop
#include "Auth.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
TAuth::TAuth()
{
}
TAuth::~TAuth()
{
}
void TAuth::TestMessage()
{
    MessageBox(0, "Test message", "Test", MB_OK);
}
和File1.cpp:

#pragma hdrstop
#pragma argsused

#include "Auth.h"
extern "C" __declspec(dllexport) void* __stdcall GetClassInstance()
{
    return static_cast<void*>(new TAuth());
}
extern "C" int _libmain(unsigned long reason)
{
    return 1;
}    
=>我还尝试将“\u stdcall”替换为“\u cdecl”或“”(删除):库加载,但GetProcAddress返回NULL


=>试图调用DLL的方法“TestMessage()”时,我做错了什么?

要从DLL正确绑定函数,您应该给出完整的定义,包括调用约定、参数、返回类型和
\u dllexport/\uu dllimport
修饰符。最简单的方法是使用
typedef
so而不是键入(在testdllauthorga.cpp中)

使用

如果使用的是
\uuu cdecl
约定,则还应在目标函数名中添加下划线

typedef __declspec(dllimport) void (__cdecl *MyFuncPointerType)(void);
MyFuncPointerType myFunc;
myFunc = (MyFuncPointerType)GetProcAddress(load, "_GetClassInstance");
您还可以显式地将
AuthParent*
定义为factory函数的返回类型,以消除对
void*
和返回到
AuthParent*
(在File1.cpp和Test\u DLLAuthOrga.cpp中)的不必要强制转换,因此,最终的代码段如下所示:

typedef __declspec(dllimport) AuthParent* (__cdecl *MyFuncPointerType)(void);
MyFuncPointerType myFunc;
myFunc = (MyFuncPointerType)GetProcAddress(load, "_GetClassInstance");
mpAuth = myFunc();

Dependency Walker说“错误:由于隐式依赖模块中缺少导出函数,至少有一个模块具有未解析的导入。错误:找到了具有不同CPU类型的模块。”因为“找不到IESHIMS.dll,并且因为所有dll都在x64中,除了我选择“Win32”作为“Plates formes cible”(“我在Embarcadero中为“Win32”平台和“Release”编译DLL,正如Dependency Walker所说,我的DLL中包含的DLL在Win64中,我在Win64 Release和Dependency中打开了DLL;因此,这“解决了”了不同的CPU类型问题,但仍然依赖沃克说,一些dll丢失;如何将它们合并到我的DLL中?
mpAuth = static_cast<AuthParent*>(myFunc);
mpAuth = (AuthParent*)myFunc;
void *myFunc;
myFunc = (void *)GetProcAddress(load, "GetClassInstance");
typedef __declspec(dllimport) void (__stdcall *MyFuncPointerType)(void);
MyFuncPointerType myFunc;
myFunc = (MyFuncPointerType)GetProcAddress(load, "GetClassInstance");
typedef __declspec(dllimport) void (__cdecl *MyFuncPointerType)(void);
MyFuncPointerType myFunc;
myFunc = (MyFuncPointerType)GetProcAddress(load, "_GetClassInstance");
typedef __declspec(dllimport) AuthParent* (__cdecl *MyFuncPointerType)(void);
MyFuncPointerType myFunc;
myFunc = (MyFuncPointerType)GetProcAddress(load, "_GetClassInstance");
mpAuth = myFunc();