DllMain Attach 和 Detach 过程中的使用限制

发布于 2024-11-04 06:55:55 字数 338 浏览 1 评论 0原文

我的一位同事在 DllMain Detach 过程中遇到了麻烦。他的错误似乎并非在所有情况下都会出现,但相当频繁。

在尝试帮助他时,我记得DllMain Attach 和 Detach 过程中的一些使用限制,但我不确定我是否记得清楚,因为这是 2 年前的技术讨论,而且不是我致力于解决这些终止问题。

也就是说,我记得我们应该:

  • 避免使用 new 和 delete 运算符并更喜欢 HGLOBAL 内存分配
  • 避免在这里处理线程终止。

如果我错了,您能否纠正我,如果有的话请解释一下,或者指出一篇可以处理这些问题的技术文章。

One colleague of mine has troubles during the DllMain Detach process. His bug seems not to appear in all cases, but fairly often.

While trying to help him, I kind of remembered of some usage limitations during the DllMain Attach and Detach process, but I am not sure I remember well since it was 2 year old technical discussions and it was not me working on thoses termination issues.

Namely I kind of remember that we should:

  • Avoid using new and delete operator and prefer HGLOBAL memory allocation
  • Avoid dealing with thread terminations here.

Could you correct me if I am wrong, explain me if ever, or point to a technical article that would deal with these issues.

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

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

发布评论

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

评论(3

祁梦 2024-11-11 06:55:55

避免调用 LoadLibrary 和相关 API。

除了 Steve 的链接之外,这里还有来自 Raymond Chen 的旧的新事物的一些不错的相关帖子:

初与友歌 2024-11-11 06:55:55

大多数问题都是由于加载器锁冲突而引起的。 DllMain 不应长时间运行,或者在可以避免的情况下使用锁。

良好的背景 这里

Most problems arise due to conflicts over the loader lock. DllMain should not be long-running, or use locks if it's avoidable.

Good background here.

骑趴 2024-11-11 06:55:55

查找有主题的文档

[1]“Dll 主入口点”

[2]“延迟加载 DLL 的约束”

[3]“动态链接库最佳实践”

[4] Jefrey Richter,Windows via C++ ,第 20 章。

(抱歉,由于 stackoverflow 政策,我无法给出 URL 引用)

摘要

  1. 也许其他 DllMain 已经执行过,也许没有。不要从其他 DLL 调用函数

  2. 不要调用以下内容:
    "FreeLibrary/LoadLibrary/CreateProcess/ExitThread/GetStringType"

  3. 不要从 User32.dll、Gdi32.dll 调用函数

  4. 如果 CRT 为未初始化不使用其中的内存管理功能
    (我认为仅限于初始化阶段)

  5. 您应该从文档中了解您所在的线程上下文。

  6. 执行以下操作是合法的:创建并初始化同步对象。打开、读取和写入文件。

Find documents with topics

[1] "Dll Main Entry Point"

[2] "Constraints of Delay Loading DLLs"

[3] "Dynamic-Link Library Best Practices"

[4] Jefrey Richter, Windows via C++, chapter 20.

(Sorry, I can not give URL references due to stackoverflow policy)

Summary

  1. Maybe other DllMain have already been executed, maybe not. Don't call functions from other DLL's

  2. Don't call the following things:
    "FreeLibrary/LoadLibrary/CreateProcess/ExitThread/GetStringType"

  3. Don't call functions from User32.dll, Gdi32.dll

  4. If CRT is not initialized don't use memory management functions from it
    (my opinion that is restricted only for initialization phase)

  5. You should understand in which thread context you are from documentation.

  6. It is legal to do the following: Create and initialize synchronization objects. Open, read from, and write to files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文