在mdi中调用在Dll中的child窗方式如何?

ljlln 2003-10-10 10:15:20
调用处:
HINSTANCE DLLInst = NULL;
String sDllNameAndPath=ExtractFileDir(Application->ExeName)+"\\ChildDll.dll";
if(!FileExists(sDllNameAndPath))
{
return ;
}
DLLInst = LoadLibrary(sDllNameAndPath.c_str());
//int(__stdcall *UpdateIntFace)(String sFilePath );
int (__stdcall *ShowForm) (TApplication* Owner) ;

if (DLLInst == NULL) return ;
ShowForm = (int(__stdcall *)(TApplication* Owner))GetProcAddress(DLLInst,"ShowForm");
try
{
ShowForm(Application) ; //导入成功 返回1 失败返回0 ;
}
catch(...)
{
FreeLibrary(DLLInst);
return ;
}
FreeLibrary(DLLInst);
return ;


dll中的接口函数:
extern "C" __declspec(dllexport) int __stdcall ShowForm(TApplication* Owner) ;
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//---------------------------------------------------------------------------
int __stdcall ShowForm(TApplication* Owner)
{
new TForm2(Owner) ;
}
老用问题!应该如何调用、谢谢!
...全文
108 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljlln 2003-10-13
  • 打赏
  • 举报
回复
有没有人有更好的建议?
ljlln 2003-10-10
  • 打赏
  • 举报
回复
HINSTANCE DLLInst = NULL;
String sDllNameAndPath=ExtractFileDir(Application->ExeName)+"\\ChildDll.dll";
if(!FileExists(sDllNameAndPath))
{
return ;
}
DLLInst = LoadLibrary(sDllNameAndPath.c_str());
//int(__stdcall *UpdateIntFace)(String sFilePath );
int (__stdcall *ShowForm) (TApplication* Owner) ;

if (DLLInst == NULL) return ;
ShowForm = (int(__stdcall *)(TApplication* Owner))GetProcAddress(DLLInst,"ShowForm");
try
{
ShowForm(Application) ; //导入成功 返回1 失败返回0 ;
//如果是Child类型、我何时释放DLL???
}
catch(...)
{
FreeLibrary(DLLInst);
return ;
}
FreeLibrary(DLLInst); ???不能在此释放!何时呀???
return ;
ljlln 2003-10-10
  • 打赏
  • 举报
回复
new TForm2(Application->MainForm ) ;
不是可以知道Parent吗?
domustdo 2003-10-10
  • 打赏
  • 举报
回复
就是 Libran() 的方法,因为调用dll中mdi窗体最大的问题就是子窗体创建后不知道谁是其parent窗体。
ljlln 2003-10-10
  • 打赏
  • 举报
回复
友情建议不要使用DLL中的MDI子窗体???
什么原因最好不使用???
ljianq 2003-10-10
  • 打赏
  • 举报
回复
《C++ Builder开发大全》中有完整例子,但是它的例子在完全编译下使用,问题多多。
ljianq 2003-10-10
  • 打赏
  • 举报
回复
int __stdcall ShowForm(TApplication* Owner)
{
Form2=new TForm2(Owner) ;
Form2->Show();
}


友情建议不要使用DLL中的MDI子窗体。
Libran 2003-10-10
  • 打赏
  • 举报
回复
修改dll中的接口函数:
TApplication *OldApp; //添加指针声明,用来保存原Application的指针
extern "C" __declspec(dllexport) int __stdcall ShowForm(TApplication* Owner) ;
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
if (reason == DLL_PROCESS_DETACH && OldApp)
Application = OldApp; // 释放DLL是恢复原Application
return 1;
}
//---------------------------------------------------------------------------
int __stdcall ShowForm(TApplication* Owner)
{
OldApp = Application; //保存原Application的指针
Application = Owner; //替换为主程序的Application,下面就可以直接用Application了
new TForm2(Application) ;
}
Behard 2003-10-10
  • 打赏
  • 举报
回复
确实是有一些问题

不过我没有看过我的程序出问题
ljlln 2003-10-10
  • 打赏
  • 举报
回复
谁有经验帮忙看一下

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧