如何解决DLL函数调用问题

发布于 2024-09-26 19:15:00 字数 158 浏览 1 评论 0原文

我有几个关于 DLL 的查询,

1)如果我在运行时加载 DLL,我猜 DLL 将位于单独的线程中,对吗?

2)如果我调用DLL中存在的函数,并且该函数需要很长时间才能返回值,那么我如何让我的应用程序线程等待DLL的函数返回值。

我该如何解决第二个问题

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

静若繁花 2024-10-03 19:15:01

你的假设是不正确的。

如果加载 DLL,然后调用其函数之一,则该调用是同步进行的,就像任何其他函数调用一样。

绝对没有理由在另一个线程中加载 DLL。当然,您可以这样做,但这不是默认设置。

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.

寂寞陪衬 2024-10-03 19:15:01

1) 不。dll 只是代码。 DLL 中的代码将在您创建的任何线程的上下文中调用。 *

2) 因此,您的应用程序将等待 dll 的函数完成。

  • 当您的应用程序调用 DLL 时,Dll 可以创建工作线程。但是,您不能直接调用线程。您的代码所做的任何调用都将始终在当前线程上同步发生。

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.
黑寡妇 2024-10-03 19:15:01

你用的是qt线程吗?否则我无法理解为什么你会使用“qt”标签。

至于你的问题,在我看来,你必须创建另一个线程来调用 DLL 中包含的函数。
当该线程退出时,您可以假设您拥有该函数的结果。

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.

冷弦 2024-10-03 19:15:01
  1. 您也可以在 switch 中实现DLL_THREAD_ATTACH
  2. 您必须从要减慢速度的线程中调用此函数,或者在函数调用之前让线程挂起,然后在函数调用之后让线程恢复。
  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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文