在DLL中调用窗体,怎样限制只能动态创建唯一窗体,窗体名称是动态的。
用Assigned时,好象参数必须是固定的,不能是动态的。
是否有什么好方法!谢谢指教。还有,DLL中的窗体为什么不能用模式窗体?

解决方案 »

  1.   

    限制为唯一的窗体很容易做到的, 至于模式窗体你要把
    exe的Application、 Screen 传递到DLL中,并替换DLL里面
    Application、Screen, 记住在dll DLL_PROCESS_DETACH还原。exe中代码
    TInitDllStruct=record
        HostApp:TApplication;
        HostScreen:TScreen;
        HostControlAtom:Pointer;
      end;function InitDllStruct:TInitDllStruct;
    begin
      with Result do begin
        HostApp:=Application;
        HostScreen:=Screen;
        HostControlAtom:=MyControlAtom;
      end;
    end;DLL中的代码
    var
     DllApp:Integer;
     DllScreen:Integer;
     DllControlAtom:Integer;procedure InitDll(const AInitDllStruct:TInitDllStruct); stdcall;
    begin
      with AInitDllStruct do begin
        Application:=HostApp;
        Screen:=HostScreen;
        MyControlAtom:=HostControlAtom;
      end;
    end;procedure UnLoadDll(Reason:Integer);
    begin
      case Reason of
        DLL_PROCESS_DETACH: begin
          Screen:=TScreen(DllScreen);
          Application:=TApplication(DllApp);
          MyControlAtom:=@DllControlAtom;
        end;
        DLL_PROCESS_ATTACH:begin
        end;
      end;
    end;begin
      DllApp:=Integer(Application);
      DllScreen:=Integer(Screen);
      DllControlAtom:=Integer(MyControlAtom);
      DllProc:=@UnLoadDll;
    end.