关于调用DLL中窗体的问题
我用DLL创建了一个窗体,但设置窗体以ShowModal()显示可以正常运行,但如果改为Show()则会报错,但我希望能够以SHOW方式显示,因为我可能还要调用其他的窗体,请问如何解决?
代码如下:
//---------------------------------------
#include <vcl.h>
#include <windows.h>
#include "Unit2.h "//fm1单元
#pragma hdrstop
#pragma argsused
extern "C " __declspec(dllexport) void __stdcall crateform(void);
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
__declspec(dllexport) void __stdcall crateform(void)
{
//Tfm1 *p;
fm1=new Tfm1(NULL);
fm1-> ShowModal();
delete fm1;
}
//---------------------------------------
> > > > 调用DLL的窗体 < < < <
void __fastcall TForm1::Btu2Click(TObject *Sender)
{
HINSTANCE h;
void __stdcall (*DllFunc)(void);
h=LoadLibrary( "Project1.dll ");
DllFunc=(void(__stdcall *)(void))GetProcAddress(h, "crateform ");
DllFunc();
FreeLibrary(h);
}
> > > > END < < < <
[解决办法]
fm1=new Tfm1(NULL);
fm1-> ShowModal(); //如果换成fm1-> Show(); 后面的delete 就会执行了
delete fm1;