Solved

Problems loading a Delphi 7 .DLL into a Delphi Project...Error.

Posted on 2007-03-26
5
1,144 Views
Last Modified: 2008-01-09
Hey there, I am having Problems Loading my dll into a delphi Project - "Application"...consisting of 1 form and a button, which onClick event should load  BudgetReport.dll which in turn should export the Procedure/Function/Routine to display a Report (QuickReport Object) on a Form - InspectionSelection.
Each time I try to run it, delphi gives me an Exception error..."Project CallingDLL.exe raised exception class EOleSysError with message 'CoInitialize has not been called'....."
Here follows the code...Can someone please help me...I've been struggling for 2 days now...and it feels like a waist.
I will greatly appreciate it.
Thank you.

library BudgetReport; // The DLL to be loaded.

uses
  SysUtils,
  Classes,
  BRCI in 'BRCI.pas' {frmBudgetReport};

Procedure ShowReport; export;
begin
      frmBudgetReport := TfrmBudgetReport.Create(nil);
  try
        frmBudgetReport.QuickRep1.Preview;
  finally
        frmBudgetReport.Free;
  end;
end;

exports ShowReport;
{$R *.res}
 
begin
end.

unit InspectionSelection; // The main Unit

interface

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

type
  TfrmInspection = class(TForm)
    btnReport: TButton;
    btnClose: TButton;
    procedure btnReportClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmInspection: TfrmInspection;

  Procedure ShowReport; external 'C:\Carab_Programming\DLL Reports\BudgetReport.dll';

implementation

//uses Math;

{$R *.dfm}

procedure TfrmInspection.btnReportClick(Sender: TObject);
var LibHandle : THandle;
    fShowReport : Procedure;
begin
  LibHandle := LoadLibrary('C:\Carab_Programming\DLL Reports\BudgetReport.dll');
  if LibHandle = 0 then
    raise Exception.Create('Unable to Load DLL...')
  else
  begin
    try @fShowReport := GetProcAddress(LibHandle, 'ShowReport');
      if @fShowReport <> nil then
        fShowReport;
    except
      on E: Exception do
        ShowMessage('Exception error: ' + E.Message);
    end;
  end;
  FreeLibrary(LibHandle);
end;

end.
0
Comment
Question by:theoscheepers
  • 3
  • 2
5 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 18791540
is this error thrown when loading dll or when executing ShowReport?

ziolko.
0
 
LVL 21

Accepted Solution

by:
ziolko earned 500 total points
ID: 18791550
anyway try this:

library BudgetReport; // The DLL to be loaded.

uses
  SysUtils,
  Classes,
  ActiveX,
  BRCI in 'BRCI.pas' {frmBudgetReport};

Procedure ShowReport; export;
begin
      frmBudgetReport := TfrmBudgetReport.Create(nil);
  try
        frmBudgetReport.QuickRep1.Preview;
  finally
        frmBudgetReport.Free;
  end;
end;

exports ShowReport;
{$R *.res}
 
begin
  CoInitialize(nil);
end.

ziolko
0
 

Author Comment

by:theoscheepers
ID: 18791717
Hey there ziolko, thanx for responding so quick, I have done that, but now it gives me an error 'External exception error c0000029' and then another error '....could not read from memmory...' What do you think?
0
 

Author Comment

by:theoscheepers
ID: 18791746
Nope, I restarted Delphi and tried again and it still gives me the same error. The program stops at fShowReport on the OnClick event of btnProcess...when I do a step through(F7) using a breakpoint it stops there giving me that error too. Shouldn't I set Parameter / Project options setting to set the file output directory or host program for the dll? Or is that only when I want to run the app / dll from within Delphi? Thanx
0
 

Author Comment

by:theoscheepers
ID: 18792166
Thanx ziolko, you did have the right answer, I just didn't change my Host Program Directory from our server to my local machine...it works perfectly!!!!!! Thanx a mill.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
A short film showing how OnPage and Connectwise integration works.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now