1:主程序登录时有个用户名变量,现在调用了一个带输入窗体的DLL,输入完一条记录时要添添加主程序中的变量用户,请问如何做,
2:在关闭DLL的输入窗体时如何把窗体上的cxtextedit1.TEXT的内容传到主程序的EDIT2.TEXT中.
我的主程序:
unit dll_tes;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  Ttest = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Edit1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  test: Ttest;
  formref:longint;
function myshowform1(ahandle:thandle):longint;stdcall;
procedure mycloseform1(aformref:longint);stdcall;implementation
function myshowform1;external 'dll_1.dll';
procedure mycloseform1;external 'dll_1.dll';{$R *.dfm}procedure Ttest.Button1Click(Sender: TObject);
begin
formref:=myshowform1(application.handle);
//showmessage(inttostr(formref));end;procedure Ttest.Button2Click(Sender: TObject);
begin   mycloseform1(formref);test.Close;end;procedure Ttest.FormClose(Sender: TObject; var Action: TCloseAction);
begin
mycloseform1(formref);
end;procedure Ttest.Edit1Change(Sender: TObject);
beginend;end.DLL的程序:
library dll_1;
uses
  SysUtils,
  ActiveX,
  windows,
  Classes,
  sgdgd_tj in 'sgdgd_tj.pas' {Form1},
  SGDGD_TJDY in 'SGDGD_TJDY.pas' {Form12};
  procedure _DllProc(Reason: Integer);
begin
  //DLL装载时调用CoInitialize
  if Reason = DLL_PROCESS_ATTACH then
    CoInitialize(nil)
  else if Reason = DLL_PROCESS_DETACH then
  //DLL卸载时调用CoUninitialize
    CoUninitialize;
end;{$R *.res}
 exports
  myshowform1,
  mycloseform1;
begin
   DLLProc := @_DllProc;
  _DllProc(DLL_PROCESS_ATTACH); //装载end.

解决方案 »

  1.   

    向DLL传,则在DLL中增加一个Procedure,DLL向主程序传,则在DLL当中加一个Callback。
    或者也可以定义消息。
      

  2.   

    向DLL传是通过函数参数传,回传用回调函数
      

  3.   

    主程序
    unit HostForm;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TfrmHost = class(TForm)
        edtUserName: TEdit;
        btnCallDLL: TButton;
        procedure btnCallDLLClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;  TOnGetUserName = procedure(NewName: PChar); stdcall;procedure TransParam(hApp: THandle; UserName: PChar;
      GetName: TOnGetUserName); stdcall; external 'Dll.Dll';var
      frmHost: TfrmHost;implementation{$R *.dfm}procedure DoGetUserName(NewName: PChar); stdcall;
    begin
      frmHost.edtUserName.Text := NewName;
    end;procedure TfrmHost.btnCallDLLClick(Sender: TObject);
    begin
      TransParam(frmHost.Handle, PChar(edtUserName.Text), DoGetUserName);
    end;end.
      

  4.   

    DLL程序
    unit DllForm;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TfrmDLL = class(TForm)
        btnOk: TButton;
        edtUserName: TEdit;
        btnCancel: TButton;
        procedure btnCancelClick(Sender: TObject);
        procedure btnOkClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;  TOnGetUserName = procedure(NewName: PChar); stdcall;procedure TransParam(hApp: THandle; UserName: PChar;
      GetName: TOnGetUserName); stdcall; export;implementation{$R *.dfm}procedure TransParam(hApp: THandle; UserName: PChar;
      GetName: TOnGetUserName);
    var
      frmDLL: TfrmDLL;
    begin
      Application.Handle := hApp;
      frmDLL := TfrmDLL.Create(nil);
      try
        frmDLL.edtUserName.Text := UserName; //修改TfrmDLL上的文本框里内容为传入的UserName
        if Assigned(GetName) and (frmDLL.ShowModal = mrOk) then
          GetName(PChar(frmDLL.edtUserName.Text)); //把文本框内容回传(回调)给exe
      finally
        frmDLL.Free;
      end;
    end;procedure TfrmDLL.btnCancelClick(Sender: TObject);
    begin
      ModalResult := mrCancel;
    end;procedure TfrmDLL.btnOkClick(Sender: TObject);
    begin
      ModalResult := mrOk;
    end;end.
      

  5.   

    TO blazingfire 
     在测试时提示:无法定位程序输入点Transparam于动态库DLL_1.DLL上.
    我是跟据你的代码,加到我现有的DLL中的.如下:
    主调程序:
    unit dll_tes;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      Ttest = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Edit1: TEdit;
        Button3: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure Button3Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;tongetusername=procedure(newname:pchar);stdcall;
    procedure transparam(happ:thandle;username:pchar;
               getname:tongetusername);stdcall;external 'dll_1.dll';var
      test: Ttest;
      formref:longint;
    function myshowform1(ahandle:thandle):longint;stdcall;
    procedure mycloseform1(aformref:longint);stdcall;implementation
    procedure togetusername(newname:pchar);stdcall;
    begin
     test.Edit1.text:=newname;
    end;function myshowform1;external 'dll_1.dll';
    procedure mycloseform1;external 'dll_1.dll';{$R *.dfm}procedure Ttest.Button1Click(Sender: TObject);
    begin
    if formref<>0 then
      begin
      mycloseform1(formref);
      formref:=myshowform1(application.handle);
      end
     else
        begin
        formref:=myshowform1(application.handle);
        end;
    end;procedure Ttest.Button2Click(Sender: TObject);
    begin
     mycloseform1(formref);
     close;
    end;procedure Ttest.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
    end;
    procedure Ttest.Button3Click(Sender: TObject);
    begin
    transparam(test.Handle ,pchar(edit1.text),togetusername);
    end;
    end.
    把你的DLL部份代码加到了sgdgd_tj.pas(DLL中的窗体)中,原DLL代码没有变化.(不知这样对不对),如下: public
        { Public declarations }
      end;
      TONGETUSERNAME=PRocedure(newname:pchar);stdcall;
      Procedure transparam(Happ:Thandle;UserName:Pchar;
       Getname:Tongetusername);stdcall;export;var
      Form1: TForm1;  function myshowform1(ahandle:thandle):longint;stdcall;
      procedure mycloseform1(aformref:longint);stdcall;implementationuses Unit2, SGDGD_TJDY;
    {$R *.dfm}Procedure TransParam(Happ:thandle;username:pchar;
      getname:tongetusername);
    var
      form1:tform1;
    begin
     Application.Handle:=happ;
      form1:=tform1.Create(nil);
      try
       form1.cxtextedit9.Text:=username;
       if assigned(getname)and(form1.showmodal=mrok)then
          getname(pchar(form1.cxTextEdit9.text));
       finally
        form1.Free;
       end;
    end;
    function myshowform1(ahandle:thandle):longint;
    var
    form1:tform1;
    begin
     application.Handle:=ahandle;
     form1:=tform1.Create(application);
     form1.ShowModal;
     result:=longint(form1);
    end;  procedure mycloseform1(aformref:longint);
       begin
        if aformref>0 then
           Tform1(aformref).free;
       end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    modalresult:=mrcancel;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
    modalresult:=mrok;
    end;另:ModalResult是不是一个模式窗体的返回值呀,它有什么用?
      

  6.   

    exe向DLL传
    dll:
    EXE中的数据传到DLL中的G_dll
    procdure GetValue( s: pchar);stdcall;
    begin
      G_dll:= s;
    end;exe:调用DLL中的GetValue过程
    GetValue(G_dll);
      

  7.   

    EXE传到DLL我现在懂了,但从DLL传到EXE不是很清楚,请叫了...
      

  8.   

    delphi 一本书叫 windows核心编程里面有吧,先申请空间,mapping,然后怎么怎么的就可以了,下这书看看,我看了又忘了,看来还是要多看书呀