嘿,我试图编写一个游戏引擎,我试图导出一个类在一个DLL中,并试图在我的主代码中使用它。就像使用loadlibrary()
函数一样。我知道如何导出和使用Dll的函数。但我想导出类,然后像使用函数一样使用它们。我不想为该类别include <headers>
然后使用它。我希望它是运行时。我有一个非常简单的类的代码,我只是用它来试验它。如何使用DLL中的导出类
#ifndef __DLL_EXP_
#define __DLL_EXP_
#include <iostream>
#define DLL_EXPORT __declspec(dllexport)
class ISid
{
public:
virtual void msg() = 0;
};
class Sid : public ISid
{
void msg()
{
std::cout << "hkjghjgulhul..." << std::endl;
}
};
ISid DLL_EXPORT *Create()
{
return new Sid();
}
void DLL_EXPORT Destroy(ISid *instance)
{
delete instance;
}
#endif
如何在我的主代码中使用这个?任何帮助将非常感激。 如果它很重要我在Visual Studio 2012.
http://stackoverflow.com/questions/110833/dynamically-importing-ac-class-from-a-dll – user2176127
虽然上面的线程很好,简而言之,您可以将接口类从dll中取出一个单独的头文件,然后通过分配给创建实例的基指针调用方法。 – 2013-11-23 11:20:37
其中的解决方案显示了如何从Dll加载函数,我已经知道了。我无法理解如何加载课程。我不知道如何加载该Create函数,因为在为此创建typdef时,我需要返回类型,但我不想包含标题。 – Xk0nSid