Lisp HUG Maillist Archive

FLI, LWW 6.0

Hi all,

I'm using FLI to acess some native win32 functions under LWW 6.0. 
Some of these functions may or may not be available depending on the Windows version. 
Is there a way to inspect the standard modules loaded (kernel32.dll, user32.dll etc.) 
before actually calling the function ? Or should I rely on the failure to call the function ?

Thanks for any clue,

Fabrice

Re: FLI, LWW 6.0

Unable to parse email body. Email id is 10077

Re: FLI, LWW 6.0

On Mon, Mar 22, 2010 at 1:15 PM, Fabrice Popineau
<fabrice.popineau@supelec.fr> wrote:
> Hi all,
> I'm using FLI to acess some native win32 functions under LWW 6.0.
> Some of these functions may or may not be available depending on the Windows
> version.
> Is there a way to inspect the standard modules loaded (kernel32.dll,
> user32.dll etc.)
> before actually calling the function ? Or should I rely on the failure to
> call the function ?
> Thanks for any clue,
> Fabrice

Hello Fabrice,

the function find-symbol below might help (if the symbol is not
exported by the dll you will get a null pointer).

Your message also reminded me of the dll inspector in
http://groups.google.ch/group/comp.lang.lisp/msg/b03e7bb580fb5b79 but
it doesn't seem to work for kernel32 or user32. It works for example
for Lispworks/gdiplus.dll, but I guess not all the libraries have the
same structure (a similar problem was reported in that thread for
msvcrt.dll).

Cheers,

Carlos

(fli:define-c-typedef (handle (:foreign-name "HANDLE"))
                      (:pointer :void))

(fli:define-c-typedef (farproc (:foreign-name "FARPROC"))
                      (:pointer
                       (:function nil :int :calling-convention :stdcall)))

(fli:define-foreign-function (get-proc-address "GetProcAddress")
    ((module HANDLE)
     (name (:pointer (:unsigned :char))))
  :result-type farproc
  :language :ansi-c
  :calling-convention :stdcall)

(fli:define-foreign-function (get-module-handle "GetModuleHandleA")
    ((name (:pointer (:unsigned :char))))
  :result-type HANDLE
  :language :ansi-c
  :calling-convention :stdcall)

(defun find-dll (dll)
  (fli:with-foreign-string
      (dll-name-ptr element-count byte-count) dll
    (declare (ignore element-count byte-count))
    (get-module-handle dll-name-ptr)))

(defun find-symbol (dll symbol)
  (fli:with-foreign-string
      (function-name-ptr element-count byte-count) symbol
    (declare (ignore element-count byte-count))
    (get-proc-address (find-dll dll) function-name-ptr)))

#+NIL (find-symbol "kernel32" "GetModuleHandleA")


Re: FLI, LWW 6.0

Unable to parse email body. Email id is 10080

Updated at: 2020-12-10 08:39 UTC