开发者

How to solve the DLL function call problem

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 s开发者_StackOverflow社区eparate 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


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.


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.


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.


  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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜