M
mustachio
Unregistered / Unconfirmed
GUEST, unregistred user!
是cbc写的,不过我想delphi下应该一样的,因为太简单了
我想实现的是:在主程序中调用一含有form的dll,并且这个dll中的form 是无模式窗体
既是show出来的,但发现如果用show的话,刚执行test(),show出dll中的form
程序就直接freelibrary了,我该怎样处理呢?
主程序中调用:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HINSTANCE hInst;
void (__stdcall*test)();
hInst = LoadLibrary("dll.dll");
if(hInst==NULL)
ShowMessage("load dll file failed");
test = (void(__stdcall*)())GetProcAddress(hInst, "test");
if(test==NULL)
ShowMessage("can't find test()");
test();
FreeLibrary(hInst);
}
//---------------------------------------------------------------------------
dll中:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <windows.h>
#include "dllfrm.h"
#pragma hdrstop
#pragma argsused
USEFORM("unit2.cpp", Form2);
extern "C" __declspec(dllexport) void __stdcall test();
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//---------------------------------------------------------------------------
void __stdcall test()
{
Form2 = new TForm2(NULL);
Form2->Show();
}
//----------------------------------------------------------------------------
dll的form中:
void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
{
Action = caFree;
}
//-----------------------------------------------------------------------------
我想实现的是:在主程序中调用一含有form的dll,并且这个dll中的form 是无模式窗体
既是show出来的,但发现如果用show的话,刚执行test(),show出dll中的form
程序就直接freelibrary了,我该怎样处理呢?
主程序中调用:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HINSTANCE hInst;
void (__stdcall*test)();
hInst = LoadLibrary("dll.dll");
if(hInst==NULL)
ShowMessage("load dll file failed");
test = (void(__stdcall*)())GetProcAddress(hInst, "test");
if(test==NULL)
ShowMessage("can't find test()");
test();
FreeLibrary(hInst);
}
//---------------------------------------------------------------------------
dll中:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <windows.h>
#include "dllfrm.h"
#pragma hdrstop
#pragma argsused
USEFORM("unit2.cpp", Form2);
extern "C" __declspec(dllexport) void __stdcall test();
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//---------------------------------------------------------------------------
void __stdcall test()
{
Form2 = new TForm2(NULL);
Form2->Show();
}
//----------------------------------------------------------------------------
dll的form中:
void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
{
Action = caFree;
}
//-----------------------------------------------------------------------------