如何在C ++中从dll(dll中的构造函数)创建某个类? [英] How to create some class from dll(constructor in dll) in C++?
本文介绍了如何在C ++中从dll(dll中的构造函数)创建某个类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从dll(dll中的构造函数)创建某个类?(C ++)
或如何从dll动态加载类?
How to create some class from dll(constructor in dll)?(C++) or how to dynamically load class from dll?
推荐答案
严格回答您的问题,您需要添加一个外部 C函数,该函数返回构造函数的结果:
Answering your question strictly, you need to add an extern "C" function that returns the result of the constructor:
extern "C" foo* __declspec(dllexport) new_foo(int x) {
return new foo(x);
}
然后在您的源代码中,可以在 new_foo上使用GetProcAddr来调用该函数
Then in your source you can use GetProcAddr on "new_foo" to call the function.
这篇关于如何在C ++中从dll(dll中的构造函数)创建某个类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文