Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

19 Experts available now in Live!

Get 1:1 Help Now