我可以将类放入 DLL 中吗?
我写的类是这样的:
class SDLConsole
{
public:
SDLConsole();
~SDLConsole(){};
void getInfo(int,int);
void initConsole(char*, char*, SDL_Surface*, int, int, int);
void sendMsg(char*,int, SDL_Surface*);
void cls(SDL_Surface*);
private:
TTF_Font *font;
SDL_Surface *consoleImg;
int width, pos, height, line, size, ctLine;
SDL_Surface* render(char*,int);
};
我知道如何加载 DLL 并使用 DLL 中的函数,但如何将类放入 DLL 中?非常感谢。
如果您使用运行时动态链接(使用 LoadLibrary 加载 dll),则无法直接访问该类,您需要为您的类声明一个接口并创建一个返回此类实例的函数,如下所示:
class ISDLConsole
{
public:
virtual void getInfo(int,int) = 0;
virtual void initConsole(char*, char*, SDL_Surface*, int, int, int) = 0;
virtual void sendMsg(char*,int, SDL_Surface*) = 0;
virtual void cls(SDL_Surface*) = 0;
};
class SDLConsole: public ISDLConsole
{
//rest of the code
};
__declspec(dllexport) ISDLConsole *Create()
{
return new SDLConsole();
}
否则,如果您在加载时链接 dll,则只需使用icecrime 提供的信息即可:http://msdn.microsoft.com/en-us/library/a90k134d.aspx http://msdn.microsoft.com/en-us/library/a90k134d.aspx
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)