本人有一个下的dll mdi窗体的例子,自己带的那个可执行文件用的正常,但是我将dll和主程序编译过后运行就出错了,估计那个例子是delphi5写的,而我用delphi6编译的。请大家来看看如何使其正常运行。
主窗体源代码如下: (窗体上一个菜单项(或按钮)StartBtn,里面一个click事件)
unit MainUnit1;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ToolWin, ComCtrls, Menus;type
  TMainForm = class(TForm)
    MainMenu1: TMainMenu;
    StartBtn: TMenuItem;
    procedure StartBtnClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;   T_ProvaChild = procedure (ParentApplication: TApplication; ParentForm: TForm); stdcall;var
  MainForm: TMainForm;implementation{$R *.DFM}procedure TMainForm.StartBtnClick(Sender: TObject);
var
   DllHandle: THandle;
   ProcAddr: FarProc;
   ProvaChild: T_ProvaChild;
begin   
   DllHandle := LoadLibrary('ProjectDll');
   ProcAddr := GetProcAddress(DllHandle, 'ProvaChild');
   if ProcAddr <> nil then
   begin
      ProvaChild := ProcAddr;
      ProvaChild(Application,Self);
   end;
end;end.
//***  DLL代码如下:
library ProjectDll;{ ...}uses
  Windows,
  Messages,
  SysUtils,
  Classes,
  Graphics,
  Controls,
  Forms,
  Dialogs,
  UnitDll in 'UnitDll.pas' {Form1};procedure ProvaChild(ParentApplication: TApplication; ParentForm: TForm); export; stdcall;
var
  Form1: TForm1;  
  DllProc: Pointer;             { Called whenever DLL entry point is called }begin
   Application:=ParentApplication;   Form1:=TForm1.Create(ParentForm);
   Form1.MyParentForm:=ParentForm;
   Form1.MyParentApplication:=ParentApplication;
//   windows.SetParent(Form1.Handle,ParentForm.Handle);
//   Form1.FormStyle:=fsMDIChild;
   Form1.Show;
end;procedure DLLUnloadProc(Reason: Integer); register;
begin
  if Reason = DLL_PROCESS_DETACH then  Application:=DllApplication;
end;exports
   ProvaChild;begin
   DllApplication:=Application;
   DLLProc := @DLLUnloadProc;
end.