?
Solved

DLL access violation

Posted on 1998-10-13
2
Medium Priority
?
400 Views
Last Modified: 2010-04-06
I am trying to put my routines into a dll.
If I do a simple thing in the dll (e.g. addition, etc)
then it works fine.But if I do a bit complex thing (e.g. passing a tquery object and making a query and returning the resultset) then it gives me the access violation error
at the third or fourth call.
Can that be a memory allocation problem.(a growing DLL cause access violation ) or any oyher thing.
any suggestion will be appreciated!
thanks in advance
0
Comment
Question by:guvencum
[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
2 Comments
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1342735
Hi

Certain things cannot be done in a DLL.  E.g. you can't make a form, query, etc. in a DLL with the owner being your main form.

Perhaps you could give some code samples.

In general, passing VCL objects (forms, queries, etc.) from your main app to a DLL is OK, but they should be created and destroyed in your main app.

Cheers,
JB
0
 
LVL 1

Accepted Solution

by:
Roadrunner100598 earned 200 total points
ID: 1342736
Hello,

I had the same problem. It's true that you cannot pass a query or database object from your main application to your DLL.

My solution was to have my own TDatabase object in my DLL as well as the TQuery. You don't need a form for this - just create the objects dynamically. The results of the query are passed by a TList to the main application.

This also solved another problem: I wanted to have BDE access from within a thread and I could not get this working (you need a second TSession...). The DLL routine can be called within a thread - it has it's own TSession it will work.

Hope you like this answere.

Beep, beep... Roadrunner
--------------------------------------
library CompanyData;

uses
  SysUtils,
  Classes,
  Windows,
  Dialogs,
  dbtables;

var
  DB     : TDatabase;

procedure GetData(ResultList:TList); stdcall; far;
var
  qry       : TQuery;
  NewItem   : TMyListItem;
begin
  if assigned(ResultList) then begin
    qry:=TQuery.Create(NIL);
    qry.DatabaseName:=DB.DatabaseName;
    qry.SQL.Text:=....
    qry.Open;

. move data into ResultList...

    qry.Free;
  end;
end;


procedure DLLHandler(Reason:integer);
begin
  case Reason of
    DLL_PROCESS_ATTACH : begin
                           DB:=TDatabase.Create(NIL);
                           DB.Name        :='dbCOMPANYS';
                           DB.LoginPrompt :=false;
                           DB.DatabaseName:='dbCOMPANYS';
                           DB.Params.Add('DATABASE NAME=dbCOMPANYS');
                           DB.AliasName   :='COMPANYS';
                           DB.Connected:=true;
                         end;
    DLL_PROCESS_DETACH : begin
                           DB.Connected:=false;
                           DB.Free;
                         end;
  end;
end;


exports
  GetData;

begin
  DLLProc:=@DLLHandler;
  DLLHandler(DLL_PROCESS_ATTACH); { Otherwise no initialization would be done }
end.

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

801 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