如果一个dll有下面这种函数,则必须使用/MD或/MDd选项链接,不能使用/MT或/MTd:
//必须使用/MD或/MDd链接选项来生成此模块,不能是/MT或/MTd
_declspec(dllexport)
int* test()
{
return new int[5];
}
否则,使用此模块的人如果有下述操作,程序运行就会崩溃:
#include <stdio.h>
#pragma comment(lib,"test.lib")
_declspec(dllimport) int* test();
int main()
{
int* p = test();
delete[]p;//如果test函数所在的dll不是用/MD或/MDd链接生成的,则销毁对象时就会导致程序崩溃
return 0;
}