473,412 Members | 5,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Loadlibrary(), function callbacks and multi-threading

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)

Apr 3 '06 #1
2 3055
Bit byte wrote:
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)
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
Apr 3 '06 #2


Carl Daniel [VC++ MVP] wrote:
Bit byte wrote:
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)

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

Thanks for the clarification

Apr 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris Morley | last post by:
Hi, I have always done my C++ class callbacks with the age old 'using this pointer in parameter of the class's static callback function' and typecasting it to get the specific instance. However...
3
by: Siegfried Heintze | last post by:
I have some C functions I need to expose as XML web services. My original plan was to deply an XML Web service in C# and use P/Invoke to call my C functions. This is not working because the web...
8
by: one2001boy | last post by:
Hello, I can use call a function with any arugment from LoadLibrary(), but not a function with argument of "FILE*. For example, I can build a .DLL dynamically loaded library with option /DDD...
8
by: ATS | last post by:
HOWTO Implement LoadLibrary\GetProcAdrress\FreeLibrary in C# Please help, I want to fully implement LoadLibrary\GetProcAdrress\FreeLibrary in C#, and be able to call functions that I use...
3
by: ATS | last post by:
HOWTO Implement LoadLibrary, GetProcAdress, and FreeLibrary. Below is code that I want to be able to use simple LoadLibrary\GetProcAddress\FreeLibrary technqiues on. I've used the code that was...
1
by: Craig Dunstan | last post by:
I am using C# to write a web service, which relies on some underlying functionality in a third party DLL. I have been reliably informed that I should not use static binding to the DLL as this will...
1
by: Siegfried Heintze | last post by:
I have some C functions I need to expose as XML web services. My original plan was to deply an XML Web service in C# or VB and use P/Invoke to call my C functions. This is not working because the...
6
by: Tushar | last post by:
Hi All, Could anyone please let me know if it is possible to load a library which has been built with a /MD compiler witch into an exe which has been build with a /ML compiler switch using...
1
by: gordon.chapman | last post by:
Yep, it's the old LoadLibrary failed problem. I understand that python24.dll is required for the executable to run, but I'm going to be building a few of these executables and I don't want to...
7
by: ghulands | last post by:
I am having trouble implementing some function pointer stuff in c++ An object can register itself for many events void addEventListener(CFObject *target, CFEventHandler callback, uint8_t...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.