TThread in Delphi DLL's with initialization/finalization

Hello,

I'm using a TThread in a (Delphi XE) DLL.

In the initialization section of a unit, I create the thread and in the
finalization section I would like to free/release/terminate the thread.

I've used this code in normal executables and then it works without any
problem.

But when I use this code in a DLL (ex. ISAPI dll), then this go wrong....

When I Free the thread in de finalization section, the finalisation/free
routine will completly lock up.
 (See example 'DLLThreadBlocking' in attached archive)

When I try a different approach, to Terminate the thread and set
'FreeOnTerminate := True', the Thread will be freed, but there will be a
memory leak. (See example 'DLLThreadMemoryLeak').

The archive containt both compiled dll's and a 'loader', which will try to
load/unload the dll.
When the dll is loaded is will show a dialog. As soon as OK is clicked the
dll is unloaded.

But anyway, it looks like something is not working correctly.
(or I'm using thread in a way, that the Os/Delphi doesn't support...)

-- 
Regards,

Ronald Hoek

Application Developer
ComponentAgro B.V.
Oud-Beijerland - The Netherlands

http://www.componentagro.nl

KvK: H24264020
0
Ronald
3/23/2011 1:55:37 PM
embarcadero.delphi.general 4258 articles. 0 followers. Follow

5 Replies
2282 Views

Similar Articles

[PageSpeed] 26

Hi,

Eventually it is the same problem the guys at RemObjects had:
http://blogs.remobjects.com/blogs/ck/2006/10/05/p121

I would suggest you add to additional functions to your
dll - an init and finalize function (like for COM uses
CoInitialize and CoUninitialize ;).

Call them just after you loaded the dll and before you unload it...
then you never have problems like that ;)

kind regards
    Mike
0
Michael
3/23/2011 4:07:15 PM
Ronald Hoek wrote:

> In the initialization section of a unit, I create the thread and in
> the finalization section I would like to free/release/terminate the
> thread.

Take a look:

http://download.microsoft.com/download/a/f/7/af7777e5-7dcd-4800-8a0a-b18336565f5b/DLL_bestprac.doc

--
Alex
0
Alex
3/23/2011 5:05:20 PM
"Ronald Hoek" <none> wrote in message news:340373@forums.embarcadero.com...

> In the initialization section of a unit, I create the thread and in the
> finalization section I would like to free/release/terminate the thread.

That is not a good thing to do inside a DLL.  You should export public 
functions for the app to call when needed instead.

-- 
Remy Lebeau (TeamB)
0
Remy
3/23/2011 7:09:40 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> "Ronald Hoek" <none> wrote in message news:340373@forums.embarcadero.com...
> 
> > In the initialization section of a unit, I create the thread and in the
> > finalization section I would like to free/release/terminate the thread.
> 
> That is not a good thing to do inside a DLL.  You should export public 
> functions for the app to call when needed instead.
> 
> -- 
> Remy Lebeau (TeamB)

Being this is an ISAPI DLL,  not much of this helps.  

The solution is to terminate your thread and waitfor in the ISAPI "TerminateExtension" procedure. This works great.  And as per Microsoft  "TerminateExtension provides a place to put code that cleans up threads or de-allocate resources"
0
Tod
9/5/2011 1:48:41 AM
Thanks for the info everybody!!!

-- 
Regards,

Ronald Hoek

Application Developer
ComponentAgro B.V.
Oud-Beijerland - The Netherlands

http://www.componentagro.nl

KvK: H24264020
0
Ronald
9/7/2011 8:27:17 AM
Reply:

Similar Artilces:

Starting 2 TThread 's directly after each other doesn't work in delphi xe2 [Edit]
(SOLVED: iLog was not thread safe.) ----- Hello, I have a very simple thread: (note: iLog just logs output -- threadsafe; not included here.) {code} unit mySimpleThread; interface uses System.Classes, System.SysUtils, System.Types, System.UITypes, System.Variants; type TmySimpleThread = class(TThread) public constructor Create(); destructor Destroy; override; private procedure Execute; override; end; implementation constructor TmySimpleThread.Create(); begin inherited Create(True); iLog('TmySimpleThread created'); end...

delphi project and dll's
Hi, Does anyone have some experience or know some tool which will implement all dll't that are used by my delphi app nto exe file and after application start to use those dll's with or withoud visibility for files (something like winlisense and xbundler tool). I don't need protection, I just need to deploy ona exe file with dll's in it! Thanks in advanced... :-? Sasa Mihajlovic schrieb: > Hi, > > Does anyone have some experience or know some tool which will implement > all dll't that are used by my delphi app nto exe file and after > ...

runtime dll's from Delphi.NET
I distribute my assembly & Borland.Deplhi.dll & Borland.VclRtl.dll to my customers. Are my customers allowed to distribute these 2 "Borland" dll's further on to their customers as part of their application? Regards Uffe Kousgaard ...

dll's in Delphi and C++Builder
Hi I was lead to believe that creating functionality as dll's in Delphi or C++ Builder, to be used by other development languages such as Microsoft C++, create problems due to some incompatibilities or different conventions. I was also told that this not true in the other direction ie MS C++ is easily usable by Delphi developers. Is this true and if so what are the problems or conventions. We have to decide in which language to develop dll's for cross-developer use. We have both Delphi and MS C++ developers in the company. Any info will be appreciated. Bennie wrote: > I w...

Delphi x64 & DLL's
Hi, I was updated one of my big application (big mean that it has a lot of forms, functions, use few vcl libraries and so) to delphi XE2 x64. In that application I have few exe files one of them is clear (don't need any dll, bpl and so) few of them are need some dll files. That file which is "clear" works excelent and few more which has clear status, but all exe files which need dll to work raise me an error: The application was unable to start correctly (0xc000007b). Click OK to close the application. In microsoft documentation this error goes from damage files o...

Where's nsoftware's IP*Works in Delphi XE?
Hello, nobody in the Installation forum seems to know. Where's nsoftware's IP*Works in Delphi XE? Cheers, Tobias [http://www.superflexible.com] Hi Tobias +1 Best Regards Claudio "Tobias Giesen" ha scritto nel messaggio news:280997@forums.embarcadero.com... > Hello, > > nobody in the Installation forum seems to know. > > Where's nsoftware's IP*Works in Delphi XE? > > Cheers, > Tobias > > [http://www.superflexible.com] Tobias Giesen wrote: > nobody in the Installation forum seems to know. >...

Nick's European webinar 'A year in the life of Delphi'
Why was this only announced in Pawel Glowacki's blog just after it finished? I am a registered D2009 developer in Europe and heard nothing in advance. Quietly burying the bad news about the 64-bit compiler? Tim Frost wrote: > Why was this only announced in Pawel Glowacki's blog just after it > finished? I am a registered D2009 developer in Europe and heard > nothing in advance. Quietly burying the bad news about the 64-bit > compiler? I got an email about it yesterday, but could not participate. I am most interested to see/hear a replay of the show. When will ...

Debugging DLL's with Delphi 2010 Debugger
new(Calcsdatamodule.Fpartsave); if Calcsaepdatamodule.Fpartsave=nil then showmessage('nil'); The debug inspect and watch shows (Calcsdatamodule.Fpartsave) as Nil however the following if statement evaluates to false. How can I get the debugger to show the correct address's. Does it have anything to do with the base image address? Thanks in advance for help Dennis McGuire <Dennis McGuire> wrote in message news:491628@forums.embarcadero.com... > new(Calcsdatamodule.Fpartsave); > if Calcsaepdatamodule.Fpartsave=nil then > showmessage('...

What's the simplest way to return a string from C/C++ DLL to Delphi?
Hello, Is the simplest way to return a string from a C/C++ DLL function, return it as a BSTR? In this case I don't have to request the string buffer size from the DLL function, allocate it on the Delphi side and send to the DLL function. If I get a BSTR, do I need to free it by SysFreeString in my Delphi code? Example: extern "C" __declspec(dllexport) BSTR __cdecl GetString() { wstring w(L"ABCDE!"); BSTR BString = SysAllocString(w.c_str()); return BString; } function GetString: TBStr; cdecl; external 'MyTest.dll' name 'GetStr...

DLL's obfuscated using DotFuscator when deployed don't work and the DLL's are easily decompiled. What to do?
I used DotFuscator Community edition that ships with VS2005 to obfuscate some of the DLL's from my PreCompiled website. When I deploy these obfuscated DLL's on the webserver, my site doesn't work. If I revert back to my old DLL's fo my precompiled website, it works fine. Secondly, the DLL's obfuscated with DotFuscator Community Edition are easily decompiled to the original source code using a decompiler like Salamander .NET decompiler (http://www.remotesoft.com/salamander/). Then, whats the use of this DotFuscator if it can't obfuscate the DLL's. Ple...

How to shall DLL's and neen't copy DLL's to BIN in serval Asp.net projects?
SOS. How to shall DLL's and neen't copy DLL's to BIN in serval Asp.net projects?Thanks...

Which .dll's can cause errors in PB .dll's
I would like to find out which .dll's (not PB .dll's) can cause errors in PB ..dll's - for example in pbvm60.dll. I know that drivers to some HP printers can cause errors in PB programs. Have a nice day! Joanna Any DLL that PB interacts with can result in errors... /ck "Joanna Owczarzak" <windows@poznan.varico.com> wrote in message news:P1Ms22iLCHA.654@forums.sybase.com... > I would like to find out which .dll's (not PB .dll's) can cause errors in PB > .dll's - for example in pbvm60.dll. > I know that drivers to some H...

Call 64bit dll's function from 32 bit delphi code on 64 bit OS
Is there any way or trick to call a function in 64 bit DLL from Delphi code? Any hardware manufacturer must compile their device drivers into 64bit code for 64 bit OS. So for example, graphic driver from NVidia is compiled to 64bit code for 64bit OS. Question is how to load 64 bit dll from 32 bit delphi code and call such function? I hope somebody has already dealing with that. Thanks > is how to load 64 bit dll from 32 bit delphi code and call such function? http://msdn.microsoft.com/en-us/library/aa384249(VS.85).aspx http://blogs.msdn.com/oldnewthing/archive/2008/10/20/9...

Third party Delphi component change IDE's font to 'system' typeface [Edit]
Hi I tried to use a third party component http://code.google.com/p/delph-sciter/ after I registered the component and tried to put it onto a form. most part of delphi IDE's font changed to 'system' typeface. I searched over web. looks like some person has the same issue before: http://groups.google.com/group/borland.public.delphi.ide/browse_thread/thread/71849ab73ec37ed2/e4c0cbac0487e919?hl=en&q=delphi+IDE+font&pli=1 Could anyone help this issue? Edited by: John Liuo on Apr 30, 2010 5:45 PM John Liuo wrote: > Hi > I tried to use a third party compo...

Web resources about - TThread in Delphi DLL's with initialization/finalization - embarcadero.delphi.general

Initialization vector - Wikipedia, the free encyclopedia
is a fixed-size input to a cryptographic primitive that is typically required to be random or pseudorandom . Randomization is crucial for encryption ...

Booting an Intel Architecture System, Part I: Early Initialization
The boot sequence today is far more complex than it was even a decade ago. Here's a detailed, low-level, step-by-step walkthrough of the boot ...

Patent US6061520 - Method and system for performing static initialization - Google Patents
... consolidating class files, the preloader identifies all &lt;clinit&gt; methods and play executes these methods to determine the static initialization ...

Tisdale on model initialization in wake of the leaked IPCC draft
Should Climate Models Be Initialized To Replicate The Multidecadal Variability Of The Instrument Temperature Record During The 20th Century? ...

Spring Environment is for initialization code only - Java Code Geeks
Since version 3.1, the Spring framework offers an abstraction towards several different sources through which you can easily configure your application: ...

Ball Invasion for iPad2 for iPad on the iTunes App Store
Get Ball Invasion for iPad2 on the App Store. See screenshots and ratings, and read customer reviews.

Stack Overflow
Stack Exchange log in - careers - chat - meta - about - faq Questions Tags Users Badges Unanswered Ask Question Top Questions interesting 325 ...

IBM System/360 - Wikipedia, the free encyclopedia
. It was the first family of computers designed to cover the complete range of applications, from small to large, both commercial and scientific. ...

ESANN - Author index
Electronic preceedings author index ESANN - European Symposium on Artificial Neural Networks [ Electronic proceedings home page ] A B C D E F ...

Using event capturing to improve Basecamp page load times
... would be best if we could avoid initializing sortables until the last possible moment, just before you start to drag a to-do. Deferring Initialization ...

Resources last updated: 1/18/2016 11:28:50 AM