caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "David Allsopp" <dra-news@metastack.com>
To: "'Matthieu Dubuget'" <matthieu.dubuget@gmail.com>, <caml-list@inria.fr>
Subject: RE: [Caml-list] External DLL call with mingw OCaml
Date: Sun, 20 Sep 2009 21:37:14 +0100	[thread overview]
Message-ID: <002001ca3a32$24167db0$6c437910$@metastack.com> (raw)
In-Reply-To: <4AB683DF.7000206@gmail.com>

Matthieu Dubuget wrote:
> Hello,
> 
> recently, I had to call a third-party DLL (Windows, mingw flavour of
> OCaml).
> It was not easy, because of symbol names decorations (I think).

It is indeed not easy - fortunately, it's a once-only thing (for each DLL)

> I'd like to know if there is a more simple way?

Not as far as I'm aware - no site I've ever seen gives a reasonable
explanation for why the "@nn" decorations are necessary (gcc or any other
compiler should be able to infer it from the header at link time, but
neither gcc nor the MS compilers provide a way to do this)

<snip>

> 3/ Import lib generation
> dlltool --input-def visa.def --dllname Visa32.dll --output-lib
> libvisa.a -k

The irony is that the -k (--kill-at) removes the @nn from the symbols :o)

<snip>

> The main problem is that it is a trial error process in order to find
> the @nn to add into visa.def.

This shouldn't be trial and error - you can work out the numbers from the C
definitions (which presumably you know as you're writing stubs). For the
most part for 32-bit code, it'll be 4 x the number of parameters to the
function but in more exact terms it's the number of bytes occupied by the
parameters (so sizeof the *type* of each arg) which you can deduce from the
.h file. Alternatively, you can just put them all as @0 initially and use
the error messages - it'll always give you the correct one (provided that
your headers are correct)

Hope this reassures, even if it doesn't offer an easier way!


David


PS This is the site I used originally -
http://www.emmestech.com/moron_guides/moron1.html though I'm not sure you'd
ever find a moron who wanted/needed to do this kind of thing!!


      reply	other threads:[~2009-09-20 20:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-20 19:34 Matthieu Dubuget
2009-09-20 20:37 ` David Allsopp [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='002001ca3a32$24167db0$6c437910$@metastack.com' \
    --to=dra-news@metastack.com \
    --cc=caml-list@inria.fr \
    --cc=matthieu.dubuget@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).