Solved

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

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 304
Sending Gmail through Delphi 3 108
oracle global variables 4 68
Controlled Assessment GCSE - desperate help needed 4 85
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…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

810 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