Solved

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

Posted on 2007-03-26
5
1,153 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Comparing dates in Delphi. Greater than/ Less than 3 301
select query - oracle 16 101
Base1 Encode/Decode 3 90
Using MMsystem To change audio input 1 21
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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