Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / April 2006

Tip: Looking for answers? Try searching our database.

Loadlibrary(), function callbacks and multi-threading

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bit byte - 03 Apr 2006 04:46 GMT
I am writing an application that requires me to load a (Win32 C) libray
and then register several call back functions.

I am loading the libary in a worker thread and then registering
functions in the worker thread in the loaded library.

Two questions

1). Does loadlibrary(0 run the executable in the same thread as the
calee (probably not)
2). Is it safe to register/call callback funcs accross threads (assuming
functions are written so as note to alter state of calee)
Carl Daniel [VC++ MVP] - 03 Apr 2006 05:22 GMT
> I am writing an application that requires me to load a (Win32 C)
> libray and then register several call back functions.
[quoted text clipped - 6 lines]
> 1). Does loadlibrary(0 run the executable in the same thread as the
> calee (probably not)

LoadLibrary doesn't "run the executable" when loading a DLL, except for the
DllMain function.  That IS run in the context of the thread that called
LoadLibrary.  Subsequent calls to fuinctions in the DLL will occur in
whatever thread(s) make the call(s) - there's no hidden thread switch back
to the thread that loaded the DLL or anything like that (in contrast with,
for example, calling into a STA-threaded COM object, where such a thread
switch does indeed occur).

> 2). Is it safe to register/call callback funcs accross threads
> (assuming functions are written so as note to alter state of calee)

As long as the callback registration mechanism is thread safe, then yes.

-cd
Bit byte - 03 Apr 2006 08:43 GMT
>>I am writing an application that requires me to load a (Win32 C)
>>libray and then register several call back functions.
[quoted text clipped - 21 lines]
>
> -cd

Thanks for the clarification

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.