Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Thread in Dll's

Posted on 2003-11-10
6
Medium Priority
?
575 Views
Last Modified: 2010-08-05
I need to develop one DLL with Thread method.  
This DLL will be used to a client side for access to a server in TCP/IP.  
In the same machine one or more applications must be to access the DLL, in a concept of three layers : application  - is the front-end to the end-user  
            DLL contain business rules and  
           server via TCP/IP.  
 
I would like to know a basic code for to begin the library with Thread method.  
If is possible, I need that DLL run in Windows and in Linux (the same code, but different compilations D7 and K3).  
 
Thanks ind advance
0
Comment
Question by:aspdoc
[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
6 Comments
 
LVL 6

Expert Comment

by:DaFox
ID: 9717845
Hi,

I would make use of the Win32API only in this case. Sth. like this:

library ThreadDLL;

uses
  Windows,
  Messages;

function ThreadFunc(Param: Pointer): DWORD; stdcall;
begin
  // place your code here !
end;

var
  hThread: THandle;
  ThreadID: DWord;

function start(): LongBool; stdcall;
begin
  if (hThread = 0) then
    hThread := CreateThread(nil, 0, @ThreadFunc, nil, 0, ThreadID);
  Result := hThread <> 0;
end;

procedure stop(); stdcall;
var
  hThreadExitCode: DWORD;
begin
  if hThread <> 0 then
  begin
    if GetExitCodeThread(hThread, hThreadExitCode) and (hThreadExitCode = STILL_ACTIVE) then
      TerminateThread(hThread, 0);
    CloseHandle(hThread);
  end;
  hThread := 0;
end;

procedure LibraryProc(Reason: Integer);
begin
  case Reason of
    DLL_PROCESS_ATTACH:
      begin
        DisableThreadLibraryCalls(HInstance);
        start;
      end;
    DLL_PROCESS_DETACH:
      stop;
  end;
end;

begin
  DllProc := @LibraryProc;
  LibraryProc(DLL_PROCESS_ATTACH);
end.

Regards,
Markus
0
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 1000 total points
ID: 9720453
this is not crossplatform
instead simply use TThread descendants
here's a small example: http://leenover.homeip.net/isapi/pas2html.dll/pas2html?File=/delphi/ThdDll/
you simply call the exported function with some params
you could also create a list of managed threads (somekind of a thread pool)
depends on what you wanna do
0
 
LVL 17

Expert Comment

by:geobul
ID: 9721443
Hi,

I can't understand why you need a thread. All apps using that dll will have their own copy of that dll and can use its exported functions when they need them instead of developing some kind of interthreading communication (between VCL threads of the apps and the DLL thread). DLL functions simply encapsulate and offer services to the calling apps. The same could be done using COM/DCOM.

Regards, Geo
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:aspdoc
ID: 9725291
Thank you, Lee_Nover

But :

a) Could you say that way to execute the thread ?  
b) That way I can come back the result of the call?
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 9726031
a) - sorry .. I don't understand the question
b) the point in working threads is you leave them running in the background and don't wait for the result
  you will be notified when the thread finishes .. that's what the AOnDone param is for
  it's a pointer to a procedure that will be called when the thread finishes
ofcourse you can change the parameter list of all the functions .. my code is merely a simple example

enjoy threading ;-)
0
 

Author Comment

by:aspdoc
ID: 9731063
Hi Geo  
 
Thanks for your comment.  
 
I will try to explain my possible problem.  
 
a) I intend to use the same code in D7 and K3;  
 
b) in Win32 the DLL is called from the IIS and by apps from end-users;  
 
c) in Linux the SO is called from the Apache and  by apps from end-users;  
 
d) in Win32 the ISS call the DLL and load to the memory a new copy of it.  
 
Question :  
 
The Apache Server running under Linux have the same way of the ISS under Win32 ( a new copy of  SO every each request from the browser ?  
 
If the answer is yes, no problem. I know enough to develop a single DLL or SO without thread.  
But, if is no, I need to develop a solution that work with multithreading.  
 
Regards,  Aspdoc
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

609 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