CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  网络通信/分布式开发

【求】带窗体的dll的创建和调用的完整实例。。。。。。。

楼主chenxzh88(小破孩)2004-09-01 10:47:43 在 Delphi / 网络通信/分布式开发 提问

本人试图将程序模块化,只要一个主界面,其它子窗体都封装在不同的DLL里,但是我没有做过不知道怎样写一个带窗体的dll,并在主窗口去调用这个dll。所以希望高手们提供一个完整的实例学习一下,谢谢。。。  
          mailaddress:           chenxzh517@yahoo.com 问题点数:50、回复次数:9Top

1 楼chenxzh88(小破孩)回复于 2004-09-01 10:53:20 得分 0

【更正】mailaddress:           chenxzh517@yahoo.com.cnTop

2 楼luke5678()回复于 2004-09-01 10:56:51 得分 25

 
   
  library   Project1;  
   
  {   Important   note   about   DLL   memory   management:   ShareMem   must   be   the  
      first   unit   in   your   library's   USES   clause   AND   your   project's   (select  
      Project-View   Source)   USES   clause   if   your   DLL   exports   any   procedures   or  
      functions   that   pass   strings   as   parameters   or   function   results.   This  
      applies   to   all   strings   passed   to   and   from   your   DLL--even   those   that  
      are   nested   in   records   and   classes.   ShareMem   is   the   interface   unit   to  
      the   BORLNDMM.DLL   shared   memory   manager,   which   must   be   deployed   along  
      with   your   DLL.   To   avoid   using   BORLNDMM.DLL,   pass   string   information  
      using   PChar   or   ShortString   parameters.   }  
   
  uses  
      SysUtils,  
      Classes,  
      Unit1   in   'Unit1.pas'   {Form1};  
   
  {$R   *.RES}  
   
  function   Returnstr:string;stdcall;  
  begin  
      with   TForm1.Create(nil)   do  
      try  
          showmodal;  
          Result   :=   trim(edit1.text);  
      finally  
          free;  
      end;  
  end;  
   
  exports  
      Returnstr;  
   
  begin  
  end.  
  这是dll的代码。  
   
   
  procedure   TForm1.Button1Click(Sender:   TObject);  
  var  
      DllHandle   :   THandle=0;  
      Rd   :   function   :   String;   stdcall;  
  begin  
      DllHandle   :=   LoadLibrary('mydll.dll');  
      if   DllHandle   >   0   then  
          @Rd   :=   GetProcAddress(DllHandle,'ShowMainForm')  
      else  
      begin  
          DllHandle   :=   0;  
          @Rd   :=   nil;  
      end;  
   
      if   (DllHandle   >   0)   and   (@Rd   <>   nil)   then  
          edit1.text   :=   Rd  
      else  
          edit1.text   :=   '';  
  end;  
  这是调用的代码。Top

3 楼luke5678()回复于 2004-09-01 11:03:16 得分 0

不好意识,上面的代码有错  
  更正以后再帖Top

4 楼chenxzh88(小破孩)回复于 2004-09-01 11:13:05 得分 0

你加我的QQ吧,我不懂的地方可以请教请教。QQ:348296115Top

5 楼luke5678()回复于 2004-09-01 11:14:19 得分 0

//你要引用的窗体  
   
  unit   unit1;  
   
  interface  
   
  uses  
  Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
  Dialogs,   StdCtrls;  
   
  type  
  TForm1   =   class(TForm)  
  Label1:   TLabel;  
  Button1:   TButton;  
  procedure   Button1Click(Sender:   TObject);  
  private  
  {   Private   declarations   }  
  public  
  {   Public   declarations   }  
  end;  
   
  var  
  Form1:   TForm1;  
  ApplicationName:   String;  
  procedure   LoadForm(Handle:   THandle;   AppName:   ShortString);   export;  
   
  implementation  
   
  {$R   *.dfm}  
  procedure   LoadForm(Handle:   THandle;   AppName:   ShortString);  
  begin  
  Application.Handle   :=   Handle;  
  ApplicationName   :=   AppName;  
  Form1   :=   TForm1.Create(Application);  
  try  
      Form1.ShowModal;  
  finally  
      Form1.Free;  
  end;  
  end;  
   
  procedure   TForm1.Button1Click(Sender:   TObject);  
  begin  
      self.close;  
  end;  
   
  end.  
   
   
  //Dll代码    
  library   usedll;  
   
  uses  
  SysUtils,  
  Classes,  
  Unit1   in   'Unit1.pas'   {Form1};  
   
  {$R   *.res}  
  exports  
      LoadForm   index   1;  
  begin  
   
  end.  
   
  //建立一个工程调用DLL  
  unit   Unit2;  
   
  interface  
   
  uses  
  Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
  Dialogs,   StdCtrls;  
  type  
  TForm2   =   class(TForm)  
  Button1:   TButton;  
  procedure   Button1Click(Sender:   TObject);  
  private  
  {   Private   declarations   }  
  public  
  {   Public   declarations   }  
  end;  
   
  var  
  Form2:   TForm2;  
      procedure   LoadForm;   external   'usedll.dll'   index   1;  
  implementation  
   
  {$R   *.dfm}  
   
  procedure   TForm2.Button1Click(Sender:   TObject);  
  begin  
      LoadForm;  
  end;  
   
  end.  
   
  Top

6 楼chenxzh88(小破孩)回复于 2004-09-01 11:38:11 得分 0

为什么我在调试的时候出现内存错误?  
  还有就是这三部分都是是独立的吗?还是所有代码都写到一个工程里面啊?Top

7 楼luke5678()回复于 2004-09-01 11:45:23 得分 0

能不能把具体抱什么错贴一下Top

8 楼zdq801104(【☆这个杀手不太冷☆】)回复于 2004-09-01 14:19:31 得分 25

我发原码给你了,记得给分哦Top

9 楼chenxzh88(小破孩)回复于 2004-09-01 14:31:24 得分 0

Error:  
        Project   Project2.exe   raised   exception   class   EOSError   with   message   'System   Error.Code:1400.无效的窗口句柄。',Process   stopped.Use   Step   or   Run   to   continue.  
   
  只要我有收获一定给分。Top

相关问题

  • dll中的窗体调用
  • 如何通过窗体的名字调用其实例?
  • 怎么把窗体编译成dll,怎么调用窗体dll?
  • 在DLL中怎样调用MDI窗体
  • 求DLL中调用窗体的例子
  • 如何调用DLL中的窗体
  • 调用DLL中窗体时的问题
  • 关于调用dll中的窗体
  • 窗体调用
  • 如何把窗体做进DLL呀,又怎么调用DLL窗体呢?

关键词

  • dll
  • 代码
  • dllhandle
  • 窗体
  • 调用
  • button1click
  • loadform
  • unit
  • tform
  • shortstring

得分解答快速导航

  • 帖主:chenxzh88
  • luke5678
  • zdq801104

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo