Lisp HUG Maillist Archive

FLI usage of stdcall functions

I seem to remember a way to do this, but can't find it in the documentation at the moment. Isn't there a way for the FLI to put the necessary tokens and byte count into the function name? It is late, so in case this isn't making any sense, here's an example:

(define-foreign-function (lib-init "LibInit")
    ()
  :result-type :void
  :calling-convention :stdcall
  :language :ansi-c)

However, the system exported to the DLL really isn't "LibInit", but rather "_LibInit@0". Does LispWorks recognize this with :stdcall and alter the function name accordingly, or do I need to do this by hand?

Jeff M.

--
massung@gmail.com

Re: FLI usage of stdcall functions

Unable to parse email body. Email id is 5096

Re: FLI usage of stdcall functions

I don't disagree. However, I'm accessing an external DLL that I don't have the source code to. Your reply leads me to believe that I'll have to manually change all the internal symbol names in the define-foreign-function calls.

Thanks, though.

Jeff M.

--
massung@gmail.com

On 12/28/05, Martin Simmons <martin@lispworks.com > wrote:

>>>>> On Wed, 28 Dec 2005 00:48:04 -0600, Jeff Massung < massung@gmail.com> said:

  Jeff> I seem to remember a way to do this, but can't find it in the documentation
  Jeff> at the moment. Isn't there a way for the FLI to put the necessary tokens and
  Jeff> byte count into the function name? It is late, so in case this isn't making
  Jeff> any sense, here's an example:

  Jeff> (define-foreign-function (lib-init "LibInit")
  Jeff>     ()
  Jeff>   :result-type :void
  Jeff>   :calling-convention :stdcall
  Jeff>   :language :ansi-c)

  Jeff> However, the system exported to the DLL really isn't "LibInit", but rather
  Jeff> "_LibInit@0". Does LispWorks recognize this with :stdcall and alter the
  Jeff> function name accordingly, or do I need to do this by hand?

The simplest solution is probably to link the dll using the
/export:LibInit=LibInit option, which makes the symbol have the unadorned
name.

--
Martin Simmons                              Email: martin@lispworks.com
LispWorks Ltd, St John's Innovation Centre    TEL:   +44 1223 421860
Cowley Road, Cambridge CB4 0WS, England.      FAX:   +44 870 2206189



Re: FLI usage of stdcall functions

Unable to parse email body. Email id is 5099

Re: FLI usage of stdcall functions

Thanks!

In fact, it actually prepended the underscore and added the @[bytes], which is fantastic!

Jeff M.

--
massung@gmail.com

On 12/28/05, Martin Simmons <martin@lispworks.com > wrote:

>>>>> On Wed, 28 Dec 2005 11:55:04 -0600, Jeff Massung < massung@gmail.com> said:

  Jeff> I don't disagree. However, I'm accessing an external DLL that I don't have
  Jeff> the source code to. Your reply leads me to believe that I'll have to
  Jeff> manually change all the internal symbol names in the define-foreign-function
  Jeff> calls.

Yes, that's the only documented way.

There is also an undocumented way:

(define-foreign-function (lib-init "LibInit" :stdcall)
     ()
   :result-type :void
   :calling-convention :stdcall
   :language :ansi-c)

Note the use of :stdcall as the "encoding" option.  This still reqires
modification of all the forms, but at least you don't need to know the number
to place after the @.

--
Martin Simmons                              Email: martin@lispworks.com
LispWorks Ltd, St John's Innovation Centre    TEL:   +44 1223 421860
Cowley Road, Cambridge CB4 0WS, England.      FAX:   +44 870 2206189



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