I would need the counterpart of 'import' to relaese the handle to a loaded DLL from newLISP to be able to delete the imported DLL.
Situation: I have unzipped a DLL to the temp-dir and used it from there.
Now I want to clean up, but the system don't let me delete it.
Any idea's?
FreeLibrary for newLISP?
FreeLibrary for newLISP?
Hans-Peter
I think I found a API method:
But what about a lisp-command:
Code: Select all
> (import "kernel32.dll" "GetModuleHandleA")
GetModuleHandleA <77E6DF37>
> (GetModuleHandleA "MyDll.dll")
13434880
> (import "kernel32.dll" "FreeLibrary")
FreeLibrary <77E6C79E>
> (FreeLibrary 13434880)
1
> (FreeLibrary 13434880)
1
> (FreeLibrary 13434880)
0
>
Code: Select all
> (import "MyDll.dll" "MyCommand")
MyCommand <5C4738>
> (freelib MyCommand)
Hans-Peter
Here a Lisp-Function:
So at least should it be native?
Code: Select all
(define (freelib dllName dllHandle freeret)
(import "kernel32.dll" "GetModuleHandleA")
(import "kernel32.dll" "FreeLibrary")
(setq dllHandle(GetModuleHandleA dllName))
(setq freeret 1)
(while (!= freeret 0)
(setq freeret(FreeLibrary dllHandle))))
Hans-Peter
After freeing the library, you could just use 'delete' to eliminate the symbol:
(delete (symbol "mycommand"))
or
(delete (sym "mycommand")) ;; can use shorter name since 8.2.7
All references to 'mycommand' in you code will be replaced with 'nil'.
But why would you do all this at all? The library would be released automatically when newLISP exits and the amount of space 'mycommand' takes is minimal, its only the symbol and one lisp cell holding the procedure address. Importing a library sevarl times wil not take up more space, but only increase its reference count and overwrite the already defined symbol.
Lutz
(delete (symbol "mycommand"))
or
(delete (sym "mycommand")) ;; can use shorter name since 8.2.7
All references to 'mycommand' in you code will be replaced with 'nil'.
But why would you do all this at all? The library would be released automatically when newLISP exits and the amount of space 'mycommand' takes is minimal, its only the symbol and one lisp cell holding the procedure address. Importing a library sevarl times wil not take up more space, but only increase its reference count and overwrite the already defined symbol.
Lutz