一个MFC的设置问题
创建一个Win32的dll工程。添加一个接口,定义如下:
class Interface1
{
public:
virtual void Fun1()=0;
virtual void Fun2(std::string str)=0;
};
接口文件中添加一个导出函数,声明如下:
extern "C" __declspec(dllexport) Interface1* CreateInterface();
添加一个类,头文件定义如下:
class Class1 : public Interface1
{
public:
void Fun1();
void Fun2(std::string str);
std::vector<std::string> m_vectorString;
};
实现文件如下:
void Class1::Fun1()
{
}
void Class1::Fun2(std::string str)
{
m_vectorString.push_back(str);
}
extern "C" __declspec(dllexport) Interface1* CreateInterface()
{
return new Class1();
}
创建一个MFC应用程序工程,添加对这个工程的依赖,以及对其.lib文件的输入设置。
添加如下代码:
Interface1* pInterface=CreateInterface();
pInterface->Fun1();
pInterface->Fun2("123");
如果MFC工程设置为Using MFC in Shared DLL,则运行正常,如果设置为Using MFC in Static Library,则调用Fun2的时候会出错。跟踪调试发现,是在Fun2函数返回的时候出错。
有没有人知道这是什么原因呢?