我的程序是这样。一个.exe主程序。  一个DLL1。一个DLL窗体。   主程序调用dll1  然后dll1调用dll窗体。
   我原先是静态调用。 一切都OK。但是。当主程序查询数据时。  DLL窗体就在等待状态,无法正常工作。必须等主程序工作结束。  我现在换成动态。代码是这样。library dll1;
uses
  Windows,
  Forms,
  Dialogs;{$R *.res}type TShowForm=Function (AHandle:THandle;ACaption:Pchar):Boolean;Stdcall;
  var
mainfrm,DllForm:THandle;
ShowForm:TShowForm;
....
....
begin
       mainfrm:=GetModuleHandle(dllform.dll');
    // mainfrm:=application.Handle;
     DllForm:=LoadLibrary(dllform.dll');
        if DllForm<>0 then
        begin
           @ShowForm:=GetProcAddress(DllForm,'ShowForm');
           ShowForm(mainfrm,'dllform');
        end        end;用主程序调用。主程序界面出不来。进程里有。但是看不到界面。如果我把dll1换成.exe
来调用dll窗体。
把       mainfrm:=GetModuleHandle(dllform.dll');换成mainfrm:=application.Handle;就可以正常出来。这是为什么还有。我一共有两上程序。一个负责数据修改。一个负责数据调用。都会调用dll1
如果用静态的。结果就是。两个程序打开。DLL窗体就会出来。我只想其中的一个程序能调用到DLL窗体。我应该怎么做。大家帮帮我吧。我搞了快两天了。查了N多资料都没法解决。
我现在想要的结果就是其中的一个程序能正常调用DLL1。并由DLL1调用DLL窗体。并且调用的DLL窗体不会因为主程序在处理工作,而去停止等候。(
因为我看别人的DLL窗体可以不受影响。)
我想用dll窗体来通过得到调用程序的PID来选择是否被调用。但是我用静态调用。怎么也取不到PID
如findform      getpid...我都试过了。不知道为什么。如何让DLL来进行判断?再一次求助。高分献上。 不够我再开贴送分。谢谢了。

解决方案 »

  1.   

    TShowForm=Function (AHandle:THandle;ACaption:Pchar):Boolean;
    这个函数也要贴出来吧。  mainfrm:=GetModuleHandle(dllform.dll');
    mainfrm:=application.Handle; 这二个是不同的。GetModuleHandle(dllform.dll')获取的是dllform.dll'在内存中的首地址
    application.Handle 是application的句柄
      

  2.   

    library FreePower;{ 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
      ShareMem,
      SysUtils,
      Classes,
      Forms,
      Unit_main in 'Unit_main.pas' {Form_main};{ procedure  SetApplication(mHandle:  THandle);
      begin  
          Application.Handle  :=  mHandle;  
      end;  }
    Function ShowForm(AHandle:THandle;ACaption:Pchar):Boolean;StdCall;
         var AForm:TForm_main;
    begin
         Result:=False;
         Application.Handle:=AHandle; 
         AForm:=TForm_main.Create(Application);         Aform.Caption:=ACaption;
             AForm.Show;
             Result:=True;end;
    Exports
         ShowForm;
    begin
    我其实也不是想要求太多。我现在暂是急需解决的就是。DLL不受主程序工作影响。主程序做事的时候,DLL也能进行工作。
      

  3.   

      楼上的大哥,你一定要帮帮我啊。我已经没办法了。GOOGLE了N多资料。都没法解决实际问题。是不是用LoadLibrary
     DLL就不会受主程序的影响?
      

  4.   

    library dll1; 
    uses 
      Windows, 
      Forms, 
      Dialogs; {$R *.res} type TShowForm=Function (AHandle:THandle;ACaption:Pchar):Boolean;Stdcall; 
      var 
    mainfrm,DllForm:THandle; 
    ShowForm:TShowForm; 
    .... 
    .... 
    begin 
          mainfrm:=GetModuleHandle(dllform.dll');  
        // mainfrm:=application.Handle; 
        DllForm:=LoadLibrary(dllform.dll'); 
            if DllForm <>0 then 
            begin 
              @ShowForm:=GetProcAddress(DllForm,'ShowForm'); 
              ShowForm(mainfrm,'dllform'); 
            end         end; mainfrm:=GetModuleHandle(dllform.dll');  这时候'dllform.dll'还没装入内存,所以返回应该是0GetModuleHandle(dllform.dll')获取的是dllform.dll'在内存中的首地址 即使是dll中,你还是用这一句:mainfrm:=application.Handle;