Solved

Loading DLLs in my own thread???

Posted on 2002-07-13
7
191 Views
Last Modified: 2010-04-04
Hi
i would be very gratefull to hear from any one who knows about loadig DLLs in a specific TThread.
*******NOT IN MAINTHREAD*********
thanks in advance :)
NIMA
0
Comment
Question by:Mohamadi
[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
  • 2
  • 2
  • +1
7 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 7151204
No problem, just do it, works fine.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 7151205
P.S: May be different, though, if the DLL has own forms in it. Never did such a thing yet...
0
 
LVL 1

Expert Comment

by:Dumani
ID: 7151295
LoadLibrary('c:\mypath\mydll.dll');
will work fine
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 12

Expert Comment

by:Lee_Nover
ID: 7151678
if you take a look at the Main function of the dll you can see it has one Reason parameter
it can have 4 values:
PROCESS_ATTACH, PROCESS_DETACH, THREAD_ATTACH, THREAD_DETACH
so you really can load a dll in a separate thread
as madshi pointed out there might be some roblems if you have some forms in there
a better way of using forms in your dlls is to make a package instead of a dll
0
 

Author Comment

by:Mohamadi
ID: 7156649
can you tell me an example??
thanks alot
nima
0
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 100 total points
ID: 7156782
type
  TFunction = function(x: Integer): Integer; stdcall;

...
var
  Func: TFunction;
  hLib: Cardinal;
  param, result: Integer;
begin
  hLib:=LoadLibrary('mylib.dll'); // load the dll dynamically
  if hLib = 0 then exit;
  try
    // now get our functions entry point
    @Func:=GetProcAddress(hLib, 'TheFunctionName');
    if @Func <> nil then
      result:=Func(param);// simply call out function var as we would any other function
  finally
    FreeLibrary(hLib);
  end;
end;

this will call the Func in the calling thread
this way the library is always loaded in the calling processes memory !

a more exact explanation here :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/dll_1o8p.asp

0
 

Author Comment

by:Mohamadi
ID: 7171303
Thanks alot :)
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
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…

710 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