views:

68

answers:

4

Hi,

i have couple of query's with respect to DLL,

1)If i load the DLL in run time, i guess DLL will be in separate thread right?

2)If i call a function present in DLL, and that function takes much time to return the value then how can i make my application thread to wait till the DLL's function return value.

How can i solve the second problem

+6  A: 

Your assumption is incorrect.

If you load a DLL, and then call one of its functions, the call is made synchronously, just like any other function call.

There is absolutely no reason why the DLL should be loaded in another thread. You may do it, of course, but this is not the default.

ereOn
A: 
  1. You can in switch implement DLL_THREAD_ATTACH too.
  2. You must call this function from thread you want to slow down, or get Thread Suspend before function call, and Thread Resume after.
Svisstack
+1  A: 

1) No. The dll is just code. The code in the dll is called in the context of whatever threads you create. *

2) As a result, your application will wait for the dll's function to complete.

  • A Dll can create worker threads as a result of your application calling the dll. However, you cannot call directly into a thread. Any call your code makes will always happen synchronously on the current thread.
Chris Becke
+1  A: 

Are you using qt threads? Otherwise I cannot understand why you would use the "qt" tag.

As for your problems it seems to me that you have to create another thread which will call the function contained in the DLL. When this thread exits than you can assume you have the function's result.

happy_emi
Yes, i am using Qt Threads. But the problem is my app thread is not waiting till it receives return from the DLL function
Shadow
what do you mean by "my app thread is not waiting?" If the Dll's functions forks a thread then maybe you are looking for the "join" call to wait for it...
happy_emi