我加載一個dll與ctypes的是這樣的:ctypes的卸載DLL
lib = cdll.LoadLibrary("someDll.dll");
當我與圖書館做,我需要將其卸載到它使用的資源。我在文檔中找到有關如何執行此操作的任何問題。我看到這個相當老的帖子:How can I unload a DLL using ctypes in Python?。我希望有一些顯而易見的東西我沒有找到,少一些破解。
我加載一個dll與ctypes的是這樣的:ctypes的卸載DLL
lib = cdll.LoadLibrary("someDll.dll");
當我與圖書館做,我需要將其卸載到它使用的資源。我在文檔中找到有關如何執行此操作的任何問題。我看到這個相當老的帖子:How can I unload a DLL using ctypes in Python?。我希望有一些顯而易見的東西我沒有找到,少一些破解。
我所發現的唯一真正有效的方法是負責撥打LoadLibrary
和FreeLibrary
。像這樣:
import ctypes
# get the module handle and create a ctypes library object
libHandle = ctypes.windll.kernel32.LoadLibraryA('mydll.dll')
lib = ctypes.WinDLL(None, handle=libHandle)
# do stuff with lib in the usual way
lib.Foo(42, 666)
# clean up by removing reference to the ctypes library object
del lib
# unload the DLL
ctypes.windll.kernel32.FreeLibrary(libHandle)
當我嘗試進行函數調用時,出現此錯誤:「ValueError:過程可能調用的參數太多(超過16個字節)」時,我的ctypes調用開始失敗「 –
調用約定是您的函數意味着什麼使用? 'WinDLL'表示'stdcall'。你的lib是'cdecl'嗎?如果是這樣,請改用'ctypes.CDLL'。 –
謝謝你的解釋。 –
您是否試過'del lib'? – Junuxx
我有,但從我引用的帖子:「我不知道,但我懷疑這卸載的dll。我猜想它只會從當前名稱空間中的名稱中刪除綁定(按照語言引用) 「我懷疑這是真的。我相當確定我需要釋放的資源仍然是開放的。 –