Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2007-03-26
5
1,151 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 216
Delphi Firemonkey Need Sample for Online Shopping Example. 2 166
Delphi Form ownership 4 111
oracle global variables 4 76
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…

860 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