Solved

DLL Connection ?

Posted on 2001-07-17
15
306 Views
Last Modified: 2013-11-23
Using D5, All update applied, ADO, SQL 2000.
I have an application with a very large complex report in a DLL. I open the dll and run the report just fine. Then close dll just fine. Show Main form and get an access violation.
I tried disconnecting the current ADO connection, then opening the DLL, run report, close dll, then open main connection again. No access violation.
I don't want to open the tables again. It is about a 10 - 15 second delay.

Is there a way that I can tell the DLL ado objects to use the ADOConnection of the main application?

I tried using a connection string int the DLL instead of an ADOConnection but got the access violoation.

Thanks,
Ross
0
Comment
Question by:bozo7
[X]
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
  • 8
  • 7
15 Comments
 

Expert Comment

by:MGOHARA
ID: 6293837
Pass the connection object(Pointer) to the DLL
0
 
LVL 1

Author Comment

by:bozo7
ID: 6293974
How?
And at design time I leave the connection property blank right? and then at runtime how do I tell the ADO object to use the connection object?

Ross
0
 

Expert Comment

by:MGOHARA
ID: 6294454
You don't have to leave it blank but on the create of the form or datamodule that holds the ADO connection object you can assign a connection string then pass the in your dll you pass the connection object you created to it. Or you can pass the connection string as a PChar and to the Dll.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:bozo7
ID: 6294568
I don't think that passing the connection string will work. I used a udl file and had the objects in the dll use the same udl as the connection object in the calling app. Still generated the error.

How do I pass the connection object to the dll? I tried passing it as a TADOConnection parameter, that did not work.

Ross
0
 

Expert Comment

by:MGOHARA
ID: 6294599
Make the dll an comserver that way you would be able to pass the connection object
0
 
LVL 1

Author Comment

by:bozo7
ID: 6294638
I don't mean to sound stupid but I don't know how to make a DLL a comserver.
Thanks for your help.

Ross
0
 
LVL 1

Author Comment

by:bozo7
ID: 6298776
I will give this another try
This is my test dll. I am attempting to pass the ado connection to the dll. It works fine in the dll it runs the query. But when it returns to the calling application it returns a access violation. The code for the calling application is below. You will notice that in that code there is a try except the except portion is not called.

library testing;

uses
  SysUtils,
  Classes,
  adodb,
  dialogs;

procedure AdminReport(DB : TADOConnection);
var Q : TADOQuery;
begin
  Q := TADOQuery.create(nil);
  try
    with q do
    begin
      Connection := DB;
      sql.add('select count(*) S from cells');
      open;
      if fieldbyname('s').value > 0 then
        showmessage('Ha')
      else
        showmessage('crap');
    end;
  finally
    freeandnil(Q);
  end;
end;

Exports
  AdminReport;
end.

Calling Application procedure

procedure TfrmMain.mniAdmitClick(Sender: TObject);
var
  LibHandle   : THandle;
  AdminReport : TAdminReport;
begin
  frmMain.hide;
  LibHandle := LoadLibrary('C:\Projects\Outcomes\Testing\testing.dll';
  try
    try
      if LibHandle = 0 then
        raise EDLLLoadError.Create('Unable to Load Admin Report');
      @AdminReport := GetProcAddress(LibHandle, 'AdminReport');
      if not (@AdminReport = nil) then
        AdminReport(dtmMain.adoMain)
      else
        RaiseLastWin32Error;
    finally
      FreeLibrary(LibHandle); // Unload the DLL.
    end;
  except
    showmessage('Help');
    raise;
  end;
end;//After this end I get an access violation!!!

Thank You
Ross
0
 
LVL 1

Author Comment

by:bozo7
ID: 6299582
I changed the parameter DB to a var parameter so the DLL procedure now looks like
procedure AdminReport(var DB : TADOConnection);

0
 

Expert Comment

by:MGOHARA
ID: 6300134
Try running outside the delphi enviroment and see what happens
0
 
LVL 1

Author Comment

by:bozo7
ID: 6300169
Same thing. I get the 'Ha' message like I should. Then a quick flash of the main form and nothing.
0
 

Expert Comment

by:MGOHARA
ID: 6300185
When I ran your could I got a Win 32 API Error
0
 
LVL 1

Author Comment

by:bozo7
ID: 6309062
I figured it out!
The AdminReport variable I had delclared like so
  TAdminReport = procedure (AHandle: THandle; var DB: TADOConnection); stdcall;

it should have been like this
  TAdminReport = procedure (AHandle: THandle; var DB: TADOConnection);

The 'stdcall' made the difference. So I am not sure what to do with points for this question.

Thanks,
Ross
0
 

Expert Comment

by:MGOHARA
ID: 6309135
Keep them if you want not a big deal
0
 
LVL 1

Author Comment

by:bozo7
ID: 6309145
I will reduce points to 75 and give you the answer for helping me.
Is that ok?
0
 

Accepted Solution

by:
MGOHARA earned 200 total points
ID: 6309147
Fine
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Performance of SQL statement 37 137
CheckListBox usage 3 81
Delphi problems to abort a printjob 9 34
IP without any Dots 1 52
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

762 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