V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
andychen20121130
V2EX  ›  问与答

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

  •  
  •   andychen20121130 · Sep 15, 2017 · 1940 views
    This topic created in 3156 days ago, the information mentioned may be changed or developed.

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

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

    4 replies    2017-09-18 14:09:23 +08:00
    momo1999
        1
    momo1999  
       Sep 15, 2017 via Android
    如果有互相依赖会死锁,没有依赖就加载吧
    ysc3839
        2
    ysc3839  
       Sep 15, 2017 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
       Sep 18, 2017
    @shuax 没有相互依赖。
    andychen20121130
        4
    andychen20121130  
    OP
       Sep 18, 2017
    @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).
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   935 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 20:30 · PVG 04:30 · LAX 13:30 · JFK 16:30
    ♥ Do have faith in what you're doing.