ADO in DLL

From: Theuns (theuns_at_softsim.co.za)
Date: 12/01/03


Date: 1 Dec 2003 01:42:39 -0800

I have one export procedure that takes on pchar string
argument(parameter) in the DLL.

This function creates a class that on its turn creates a datamodule
that connects to a Access database , it get some data from the DB and
generates a jpg object and save it on the harddrive.
When the procedure is finished the DLL get lots of DLL_THREAD_ATTACH
calls and create new threads untill it I get a Acces
Violation.(Creates about 3 threads)

Previously I did get "Coinitialze not called" when the datamodule is
created , I added ActiveX unit and called Coinitialze(nil), end of
that problem.

How do I fix this problem.

This is my Library code

library MYDLL;

uses
  ActiveX ,
  SysUtils,
  Classes,
  Windows,
  Jpeg,
  Dialogs,
  unMyUnit in '..\lib\unMYUnit.pas';

var
  aMyObjectClass : TMyObjectClass ;
  SaveDllProc: Pointer;
{$R *.res}

Procedure CreateJpeg(aPointerStr : PChar) ;
var
  aJpeg : TJPEGImage ;
  aStr : String ;
Begin
  aStr := aPointerStr ;
  Try
    ShowMessage(aStr);
    aJpeg := TJPEGImage.Create ;
    if not Assigned(aMyObjectClass) then
    Begin
      aMyObjectClass := TMyObjectClass.create('',46,True,True,True);
    end ;

    aMyObjectClass.Str := aStr ;

    if aMyObjectClass.SymbolOK then
    Begin
      aJpeg.Assign(aMyObjectClass.BMP);
      aJpeg.SaveToFile('C:\Projects\JPEGs\1234.jpg');
    end ;
  finally

    FreeAndNil(aJpeg);
  end ;
end ; //When Exit here get lots of Process Attach Calls

procedure Init_Destroy(Reason: Integer);
begin
  if Reason = DLL_PROCESS_DETACH then
  begin
    aMyObjectClass.Free ;
    aMyObjectClass := nil ;
    ShowMessage('MyObjectClass Freed');
    DllProc := SaveDllProc ;
  end;

  if Reason = DLL_PROCESS_ATTACH then
  begin
  end;
end;

Exports
  CreateJpeg ;

begin
  CoInitialize(nil) ;
  SaveDllProc := @Dllproc ;
  DllProc := @Init_Destroy ;
  Init_Destroy(DLL_PROCESS_ATTACH);
end.



Relevant Pages

  • Problems with ADO in DLL (Threads)
    ... I have one export procedure that takes on pchar string ... When the procedure is finished the DLL get lots of DLL_THREAD_ATTACH ... Previously I did get "Coinitialze not called" when the datamodule is ... aStr: String; ...
    (borland.public.delphi.database.ado)
  • ADO in a DLL
    ... Using Delphi 6 and trying to use ADO in a DLL. ... DataModule with a TADOConnection accessing SQLserver. ... calling Form then there is no problem. ...
    (borland.public.delphi.database.ado)
  • Re: Equivalent to VCLs DataModule
    ... DataModule is a design-time visual container for non-GUI components, ... while for a Dll at run-time it is the programmer's responsibility ... like the ability to manipulate it at design time, ...
    (microsoft.public.dotnet.framework)
  • Re: ADO in a DLL
    ... Using Delphi 6 and trying to use ADO in a DLL. ... DataModule with a TADOConnection accessing SQLserver. ... calling Form then there is no problem. ...
    (borland.public.delphi.database.ado)