在Dll中直接导出窗体类失败,该怎么处理
在Dll中直接导出窗体类失败
在BCB 2007中创建一个Dll, (VCL+多线程), 加入一个窗体,加入__declspec( dllexport),让其输出
#ifndef Unit5H
#define Unit5H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class __declspec( dllexport) TForm5 : public TForm
{
__published: // IDE-managed Components
private: // User declarations
public: // User declarations
__fastcall TForm5(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm5 *Form5;
//---------------------------------------------------------------------------
#endif
编译都没有问题,但在应用程序调这个Dll时,New一个对象的时候提示地址访问出错.
TForm5 *frmTemp = TForm5(NULL);
同时,输出线程类也是一样,就是一个线程类继承自TThread类,也是一样的错误。
请问各位大虾,是什么问题
------解决方案--------------------
DLL有独立的栈,创建new或del都放在dll内部,
------解决方案--------------------
在DLL的CPP中
在使用DLL的时候,只要调用showForm()这个方法就可以
------解决方案--------------------
ARIKA 正解。DLL 程序在 CB 对象层次和外部是隔离的。外部程序可以取出对象地址,但你不能直接访问。恐怕你那层封装省不了。
在BCB 2007中创建一个Dll, (VCL+多线程), 加入一个窗体,加入__declspec( dllexport),让其输出
#ifndef Unit5H
#define Unit5H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class __declspec( dllexport) TForm5 : public TForm
{
__published: // IDE-managed Components
private: // User declarations
public: // User declarations
__fastcall TForm5(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm5 *Form5;
//---------------------------------------------------------------------------
#endif
编译都没有问题,但在应用程序调这个Dll时,New一个对象的时候提示地址访问出错.
TForm5 *frmTemp = TForm5(NULL);
同时,输出线程类也是一样,就是一个线程类继承自TThread类,也是一样的错误。
请问各位大虾,是什么问题
------解决方案--------------------
DLL有独立的栈,创建new或del都放在dll内部,
------解决方案--------------------
在DLL的CPP中
#include "Form5.h"
....
extern "C" int __declspec(dllexport) __stdcall showForm(...)
{
...
TForm5 *frmTemp = new TForm5(NULL);
...
frmTemp->ShowModel();
delete frmTemp;
}
在使用DLL的时候,只要调用showForm()这个方法就可以
------解决方案--------------------
ARIKA 正解。DLL 程序在 CB 对象层次和外部是隔离的。外部程序可以取出对象地址,但你不能直接访问。恐怕你那层封装省不了。