V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
andychen20121130
V2EX  ›  问与答

dll 中加载另一个 dll 文件的问题

  •  
  •   andychen20121130 · 2017-09-15 17:17:09 +08:00 · 1371 次点击
    这是一个创建于 2408 天前的主题,其中的信息可能已经有所发展或是发生改变。

    看了网上都说不建议在 dllmain 中使用 loadLibrary,freeLibrary 函数。

    如果不在 dllmain 加载,应该在什么地方加载呢?

    4 条回复    2017-09-18 14:09:23 +08:00
    shuax
        1
    shuax  
       2017-09-15 18:58:22 +08:00 via Android
    如果有互相依赖会死锁,没有依赖就加载吧
    ysc3839
        2
    ysc3839  
       2017-09-15 22:02:55 +08:00 via Android
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms682583(v=vs.85).aspx
    Calling functions that require DLLs other than Kernel32.dll may result in problems that are difficult to diagnose. For example, calling User, Shell, and COM functions can cause access violation errors, because some functions load other system components. Conversely, calling functions such as these during termination can cause access violation errors because the corresponding component may already have been unloaded or uninitialized.
    andychen20121130
        3
    andychen20121130  
    OP
       2017-09-18 14:07:35 +08:00
    @shuax 没有相互依赖。
    andychen20121130
        4
    andychen20121130  
    OP
       2017-09-18 14:09:23 +08:00
    @ysc3839 在几个步骤中加载吗?

    A process loads the DLL (DLL_PROCESS_ATTACH).
    The current process creates a new thread (DLL_THREAD_ATTACH).
    A thread exits normally (DLL_THREAD_DETACH).
    A process unloads the DLL (DLL_PROCESS_DETACH).
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1135 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:41 · PVG 07:41 · LAX 16:41 · JFK 19:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.