FreeLibrary for newLISP?

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

FreeLibrary for newLISP?

Post by HPW »

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?
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

I think I found a API method:

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
>
But what about a lisp-command:

Code: Select all

> (import "MyDll.dll" "MyCommand")
MyCommand <5C4738>
> (freelib MyCommand)
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Here a Lisp-Function:

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))))
So at least should it be native?
Hans-Peter

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Thanks Lutz for the additional info.

>But why would you do all this at all?

I was not after freeing the reference to get more mem-space in newlisp.
I unzip the DLL into the temp-dir and want to free the disk-space.
And I can only delete it when it is no more referenced.
Hans-Peter

Locked