🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.language.objectpascal
Article #32425

Re: LoadLibrary() fails with EApplicationError Exception

#32425
From: Peter Below (TeamB)
Date: Fri, 22 Nov 2002 18:43
85 lines
3086 bytes
In article <3dddd294$1@newsgroups.borland.com>, Gerke Preussner wrote:
> I used Delphi 5 for quite a long time and successfully implemented
> plugin-based programs in the past. I'm currently migrating to Delphi 7 and
> trying to write a small generic plugin system. Unfortunately, i have
> difficulties getting it to work properly.
> 
> Basically, the main program contains a control that will look for DLLs in
> the program folder and load them as plugins. The DLLs contain forms which
> will then be opened by the main program on demand. Loading the DLLs doesn't
> work and the LoadLibrary() function stops with the following exception:
> 
>    "Cannot create application object in shared object or library"

You have managed somehow to create a CLX DLL project. I just did a quick test 
with D7 and it works without any problems in a VCL project.

library TestDLL;

uses
  SysUtils,
  Classes,
  DLLUnit2 in 'DLLUnit2.pas' {Form2};

{$R *.res}
exports
  CreateDLLForm;

begin
end.

unit DLLUnit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm2 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

Procedure CreateDLLForm;

implementation

{$R *.dfm}
Procedure CreateDLLForm;
  Begin
    With TForm2.Create(Application) Do
    try
      ShowModal
    finally
      free
    end;
  End;

end.

Testroutine in host app:

procedure TForm1.Button1Click(Sender: TObject);
var
  hLib: THandle;
  proc: Procedure;
begin
  hLib:= LoadLibrary( 'testdll.dll');
  if hLib <> 0 Then begin
    @proc := GetProcAddress( hLib, 'CreateDLLForm' );
    If Assigned( proc ) Then
      proc;
  end;
end;

--
Peter Below (TeamB)  
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Technical Details
Message-ID: <VA.00009662.00864a9d@antispam.compuserve.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-05!sn-xit-06!sn-xit-08!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!news.stealth.net!news.stealth.net!fu-berlin.de!news.uni-x.net!newsgroups.borland.com!not-for-mail
References: <3dddd294$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109d30,fb934d5e10fdceed
X-Google-Attributes: gid109d30,public
X-Google-ArrivalTime: 2002-11-22 11:15:49 PST
Date: Fri, 22 Nov 2002 19:43:31 +0100
Newsgroups: borland.public.delphi.language.objectpascal
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Newsreader: Virtual Access by Atlantic Coast PLC, http://www.atlantic-coast.com/va
Organization: TeamB
Message-ID: <VA.00009662.00864a9d@antispam.compuserve.com>
Subject: Re: LoadLibrary() fails with EApplicationError Exception
From: "Peter Below (TeamB)" <100113.1101@compuXXserve.com>
Reply-To: 100113.1101@compuXXserve.com
References: <3dddd294$1@newsgroups.borland.com>
NNTP-Posting-Host: 62.226.189.68
X-Trace: newsgroups.borland.com 1037990601 62.226.189.68 (22 Nov 2002 10:43:21 -0800)
Lines: 87
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-05!sn-xit-06!sn-xit-08!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!news.stealth.net!news.stealth.net!fu-berlin.de!news.uni-x.net!newsgroups.borland.com!not-for-mail