From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 26DCDBBAF for ; Sun, 20 Sep 2009 22:37:22 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiwCAIcvtkpRZ90vkWdsb2JhbACaeAEBAQEJCwoHEwOxaIQbBYFY X-IronPort-AV: E=Sophos;i="4.44,419,1249250400"; d="scan'208";a="33148035" Received: from mtaout01-winn.ispmail.ntl.com ([81.103.221.47]) by mail2-smtp-roc.national.inria.fr with ESMTP; 20 Sep 2009 22:37:21 +0200 Received: from aamtaout02-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout01-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20090920203721.UPVW6742.mtaout01-winn.ispmail.ntl.com@aamtaout02-winn.ispmail.ntl.com>; Sun, 20 Sep 2009 21:37:21 +0100 Received: from romulus.metastack.com ([81.102.132.77]) by aamtaout02-winn.ispmail.ntl.com (InterMail vG.2.02.00.01 201-2161-120-102-20060912) with ESMTP id <20090920203721.NZTY21638.aamtaout02-winn.ispmail.ntl.com@romulus.metastack.com>; Sun, 20 Sep 2009 21:37:21 +0100 Received: from Tenor ([172.16.0.8]) (authenticated bits=0) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id n8KKbHdd022771 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Sun, 20 Sep 2009 21:37:18 +0100 From: "David Allsopp" To: "'Matthieu Dubuget'" , References: <4AB683DF.7000206@gmail.com> In-Reply-To: <4AB683DF.7000206@gmail.com> Subject: RE: [Caml-list] External DLL call with mingw OCaml Date: Sun, 20 Sep 2009 21:37:14 +0100 Message-ID: <002001ca3a32$24167db0$6c437910$@metastack.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Aco6KXHAlkdFoLTYQUyuZrPoq9rjDQAB4x6Q Content-Language: en-gb Organization: MetaStack Solutions Ltd. X-Scanned-By: MIMEDefang 2.65 on 81.102.132.77 X-Cloudmark-Analysis: v=1.0 c=1 a=yaQSoiaKOV8A:10 a=fOj748EgAAAA:8 a=Ihn548MSPlnSABMHvPsA:9 a=xnjwCpUs7_IhvOgsLBwA:7 a=3x3zKKs3K_z_L11nIQGspcu_OPkA:4 a=5blDNUfTmPUA:10 a=1kF2nt7gxzc3mjHK:21 a=efjyd77oXuMSPnqV:21 X-Spam: no; 0.00; mingw:01 ocaml:01 matthieu:01 dubuget:01 mingw:01 ocaml:01 gcc:01 compiler:01 gcc:01 lib:01 def:01 --dllname:01 def:01 stubs:01 sizeof:01 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) > 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) > 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!!