delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/04/17/06:16:46

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-Authentication-Warning: localhost.localdomain: ronald owned process doing -bs
Date: Thu, 17 Apr 2003 11:33:42 +0200 (CEST)
From: Ronald Landheer-Cieslak <ronald AT landheer DOT com>
X-X-Sender: ronald AT localhost DOT localdomain
To: Lester Ingber <ingber AT ingber DOT com>
cc: cygwin AT cygwin DOT com
Subject: Re: why use __stdcall?
In-Reply-To: <20030416171045.GA3056@ingber.com>
Message-ID: <Pine.LNX.4.44.0304171121270.12359-100000@localhost.localdomain>
MIME-Version: 1.0

On Wed, 16 Apr 2003, Lester Ingber wrote:
> When using Cygwin to produce DLLs for use in other software (Excel,
> TradeStation, Maple), etc., is it necessary to insert __stdcall between
> types/typedefs and function names?  I'm just considering vanilla C code
> that runs on all platforms I've tested.
> 
> If so, is it necessary to introduce __stdcall for all functions, or only
> those that are actually called by those utilities (and these call other
> C functions, etc.).  I.e., do I have to rewrite lots of good working C
> code to introduce __stdcall throughout all code?
No. Generally you can handle it with a couple of compiler flags and 
perhaps a well-written .def file.

> If I do not use __stdcall (I do not seem to need this for simple cases?),
> what dangers lurk?
Stack corruption.

What you need to is make sure that the calling convention used by your 
function is the same as the one expected by the calling program. A 
well-placed -mrtd will do the trick if you want the stdcall convention 
without the name mangling - this works for JNI DLLs and, I think, will 
probably work for Excel-invoked DLLs as well.

> To be explicit, I am creating DLLs and .def files using scripts like:
> set module = mydll
> gcc -c ${module}.c
    ^^^ add -mrtd here

> set old_lib = ${module}.o
> gcc -shared -mno-cygwin -o ${module}.dll \
>     -Wl,--out-implib=lib${module}.a \
>     -Wl,--export-all-symbols \
>     -Wl,--export-dynamic \
>     -Wl,--add-stdcall-alias \
>     -Wl,--enable-auto-import \
>     -Wl,--output-def=${module}.def \
>     -Wl,--whole-archive ${old_lib} \
>     -Wl,--no-whole-archive ${dependency_libs}
> 
HTH

rlc



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019