выгрузка DLL из DLL

Discussion in 'WASM.WIN32' started by slow, Jan 17, 2006.

  1. slow

    slow New Member

    Blog Posts:
    0
    Возможно ли корректно инициировать выгрузку DLL из самой DLL так, чтобы она обязательно выгрузилась?



    Если можно, кусочек кода на закуску.



    Заранее благодарен
     
  2. bogrus

    bogrus Active Member

    Blog Posts:
    0
    Можно попробовать так (самому выгрузится, а адрес возврата укажет на exe)
    Code (Text):
    1.             stdcall [GetModuleHandle],dll_name
    2.             xchg    eax,[esp]
    3.             push    eax
    4.             jmp     [FreeLibrary]
     
  3. Sickle

    Sickle New Member

    Blog Posts:
    0
    можно сделать инжект кода в exe и из него вызвать

    freelibrary
     
  4. Ms Rem

    Ms Rem New Member

    Blog Posts:
    0
    А в MSDN никто не догадался заглянуть?


    Code (Text):
    1. The FreeLibraryAndExitThread function decrements the reference count of a loaded dynamic-link library (DLL) by one, just as FreeLibrary does, then calls ExitThread to terminate the calling thread. The function does not return.
    2.  
    3.  
    4. void FreeLibraryAndExitThread(
    5.   HMODULE hModule,
    6.   DWORD dwExitCode
    7. );
    8.  
    9. Parameters
    10. hModule
    11. [in] Handle to the DLL module whose reference count the function decrements. The LoadLibrary or GetModuleHandle function returns this handle.
    12. dwExitCode
    13. [in] Exit code for the calling thread.
    14. Return Values
    15. This function does not return a value. Invalid module handles are ignored.
    16.  
    17. Remarks
    18. The FreeLibraryAndExitThread function allows threads that are executing within a DLL to safely free the DLL in which they are executing and terminate themselves. If they were to call FreeLibrary and ExitThread separately, a race condition would exist. The library could be unloaded before ExitThread is called.
    19.  
    20.  
     
  5. slow

    slow New Member

    Blog Posts:
    0
    Ms Rem

    FreeLibraryAndExitThread не решает проблемы по крайней мере в том варианте применения, который есть у меня. Если я в DLL

    в каком-то месте ставлю вызов этой функции, у меня DLL выгружается но вместе с приложением. Я пробовал вызывать эту функцию в отдельном потоке но все равно вылетает с приложением.

    Sickle

    хорошая идея, надо попробовать

    bogrus

    попробуем
     
  6. slow

    slow New Member

    Blog Posts:
    0
    Если кому интересно.



    VirtualAlloc, вызванная из DLL, выделяет память в процессе, в АП которого загружена DLL. Так что проблема почти решилась
     
  7. Sickle

    Sickle New Member

    Blog Posts:
    0
    почти? а какие еще проблемы остались?
     
  8. slow

    slow New Member

    Blog Posts:
    0
    Sickle

    код дописать :))