DLL unloading itself

后端 未结 4 1395
不思量自难忘°
不思量自难忘° 2020-12-03 16:33

Is it possible for a function that is inside a DLL to unload the DLL? I need to do this so I can make sure the DLL is not in use, then write to the DLL\'s file.

4条回答
  •  佛祖请我去吃肉
    2020-12-03 16:44

    Use this when the dll has done it job:

        CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)FreeLibrary, &__ImageBase, 0, NULL);
        // terminate if dll run in a separate thread ExitThread(0); 
        // or just return out the dll
    

    And the __ImageBase is your dll's PE header structure:

    EXTERN_C IMAGE_DOS_HEADER __ImageBase;
    

提交回复
热议问题