public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* RE: __stdcall functions in relocatable DLLs
@ 1998-01-11 20:11 Stephan Mueller
  0 siblings, 0 replies; 7+ messages in thread
From: Stephan Mueller @ 1998-01-11 20:11 UTC (permalink / raw)
  To: 'Joao Pedro Sousa', Jason Alan Nordwick; +Cc: gnu-win32

Note also that functions declared with __stdcall have an underscore prefixed
and an at sign followed by argument byte count suffxed, in the DLL.  So
	int func(int a, double b)
in your source becomes
	_func@12
in the DLL.

For varargs functions, the caller must clear the stack, since the callee
can't know how many bytes to pop.  In these cases, __stdcall becomes
standard C calling convention (__cdecl in some compilers.)

In general, functions exported from a DLL can be __cdecl.

There are numerous other calling conventions, but many of them are obsolete.
Amongst the many that are or were at one time available on Windows platforms
through Microsoft compilers:
	__pascal	(args left to right, callee cleans stack)
	__fortran	(synonym for __pascal)
	__syscall	(definitely obsolete)
	__fastcall	(first few args passed in registers)
	__thiscall	(C++; 'this' passed in ECX)

stephan(not speaking for, just working for, my employer);

> -----Original Message-----
> From:	Joao Pedro Sousa [SMTP:js@servisoft.pt]
> Sent:	Sunday, January 11, 1998 12:58 PM
> To:	Jason Alan Nordwick
> Cc:	gnu-win32@cygnus.com
> Subject:	Re: __stdcall functions in relocatable DLLs
> 
> At 09:48 11-01-1998 -0800, Jason Alan Nordwick wrote:
> >
> >Is there anywhere or anything that explains the different calling
> >conventions ?
> 
> __stdcall is the Win32 function calling convention. It specifies that
> function parammeters are pushed on the stack from right to left, and the
> called function cleans up the stack on function exit. On some
> architectures
> (e.g. i386) this can be slightly faster by using a special instruction
> that
> returns from the function and removes a specified number of bytes from the
> stack (ret n).
> The "normal" C calling convention places the burden of cleaning the stack
> on the caller side.
> 
> By the way, anyone knows if exported functions on a DLL MUST be __stdcall?
> Can they be C calling convention?
> 
> --
> JPSousa
> -
> For help on using this list (especially unsubscribing), send a message to
> "gnu-win32-request@cygnus.com" with one line of text: "help".
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: __stdcall functions in relocatable DLLs
  1998-01-11 13:15   ` Joao Pedro Sousa
@ 1998-01-12  4:59     ` Benjamin Riefenstahl
  0 siblings, 0 replies; 7+ messages in thread
From: Benjamin Riefenstahl @ 1998-01-12  4:59 UTC (permalink / raw)
  To: gnu-win32

Hi Joao,

Joao Pedro Sousa wrote:
> By the way, anyone knows if exported functions on a DLL MUST be __stdcall?
> Can they be C calling convention?

They can be anything you want. The OS API uses the __stdcall convention,
so any language that supports import of DLL functions must support it.
For some languages, especially embedded languages like VBA, it's the
only supported calling convention so if you care about mixed language
programming, you should prefer using __stdcall for exported functions.

so long, benny
======================================
Benjamin Riefenstahl (benny@crocodial.de)
Crocodial Communications EntwicklungsGmbH
Ophagen 16a, D-20257 Hamburg, Germany
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: __stdcall functions in relocatable DLLs
@ 1998-01-12  2:57 Sergey Okhapkin
  0 siblings, 0 replies; 7+ messages in thread
From: Sergey Okhapkin @ 1998-01-12  2:57 UTC (permalink / raw)
  To: 'Joao Pedro Sousa'; +Cc: gnu-win32

Joao Pedro Sousa wrote:
> By the way, anyone knows if exported functions on a DLL MUST be __stdcall?
> Can they be C calling convention?
> 

They mustn't. For example, cygwin.dll exports __cdecl functions.

-- 
Sergey Okhapkin, http://www.lexa.ru/sos
Moscow, Russia
Looking for a job.


-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: __stdcall functions in relocatable DLLs
  1998-01-11  9:41 ` Jason Alan Nordwick
  1998-01-11 13:15   ` Joao Pedro Sousa
@ 1998-01-11 23:40   ` Fergus Henderson
  1 sibling, 0 replies; 7+ messages in thread
From: Fergus Henderson @ 1998-01-11 23:40 UTC (permalink / raw)
  To: Jason Alan Nordwick; +Cc: Joao Pedro Sousa, gnu-win32

On 11-Jan-1998, Jason Alan Nordwick <nordwick@graft.XCF.Berkeley.EDU> wrote:
> 
> Is there anywhere or anything that explains the different calling
> conventions ?

Yes, see "function attributes" in the "C extensions" section of the
gcc manual, in particular the `stdcall', `cdecl', and `regparm(N)'
attributes.  See also the documentation for the `-mregparm' and
`-rtd' options under "i386 options" in the "Submodel options
(Harware Models and Configurations)" subsection of the "Invoking GCC
(GNU CC Command Options)" section.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: < http://www.cs.mu.oz.au/~fjh >   |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: __stdcall functions in relocatable DLLs
  1998-01-11  9:41 ` Jason Alan Nordwick
@ 1998-01-11 13:15   ` Joao Pedro Sousa
  1998-01-12  4:59     ` Benjamin Riefenstahl
  1998-01-11 23:40   ` Fergus Henderson
  1 sibling, 1 reply; 7+ messages in thread
From: Joao Pedro Sousa @ 1998-01-11 13:15 UTC (permalink / raw)
  To: Jason Alan Nordwick; +Cc: gnu-win32

At 09:48 11-01-1998 -0800, Jason Alan Nordwick wrote:
>
>Is there anywhere or anything that explains the different calling
>conventions ?

__stdcall is the Win32 function calling convention. It specifies that
function parammeters are pushed on the stack from right to left, and the
called function cleans up the stack on function exit. On some architectures
(e.g. i386) this can be slightly faster by using a special instruction that
returns from the function and removes a specified number of bytes from the
stack (ret n).
The "normal" C calling convention places the burden of cleaning the stack
on the caller side.

By the way, anyone knows if exported functions on a DLL MUST be __stdcall?
Can they be C calling convention?

--
JPSousa
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: __stdcall functions in relocatable DLLs
  1998-01-10 17:22 Joao Pedro Sousa
@ 1998-01-11  9:41 ` Jason Alan Nordwick
  1998-01-11 13:15   ` Joao Pedro Sousa
  1998-01-11 23:40   ` Fergus Henderson
  0 siblings, 2 replies; 7+ messages in thread
From: Jason Alan Nordwick @ 1998-01-11  9:41 UTC (permalink / raw)
  To: Joao Pedro Sousa; +Cc: gnu-win32

Is there anywhere or anything that explains the different calling
conventions ?

thanks,
jay
-- 
Join the FreeBSD Revolution.
Support the FSF, buy GNU.
http://xcf.berkeley.edu/
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* __stdcall functions in relocatable DLLs
@ 1998-01-10 17:22 Joao Pedro Sousa
  1998-01-11  9:41 ` Jason Alan Nordwick
  0 siblings, 1 reply; 7+ messages in thread
From: Joao Pedro Sousa @ 1998-01-10 17:22 UTC (permalink / raw)
  To: gnu-win32

[I know this has been discussed before, but after 3 days of reading
everything I could find about it on the archives and not being able to
solve my problem I'm resorting to the mailing-list]

I'm running b18 on Win95 with Sergey's Coolview.
I'm trying to build a relocatable DLL containing some functions that use
the __stdcall calling convention.
To build the DLL I use the following commands on my Makefile:

LIBCYGWINPATH = /gnuwin32/b18/H-i386-cygwin32/i386-cygwin32/lib
CYGNUSLIBS =  -lc -lcygwin -lkernel32 -lc
$(EXECUTABLE).dll: dll_init.o dll_fixup.o $(OBJS)
	ld --base-file $(EXECUTABLE).base                   \
         --dll                                            \
         -o $(EXECUTABLE).dll                             \
         $(OBJS) dll_init.o dll_fixup.o \
         -L$(LIBCYGWINPATH)                               \
         $(CYGNUSLIBS)                                    \
         -e _dll_entry@12
	dlltool -k --dllname $(EXECUTABLE).dll \
              --def $(EXECUTABLE).def        \
              --base-file $(EXECUTABLE).base \
              --output-exp $(EXECUTABLE).exp
	ld --base-file $(EXECUTABLE).base                   \
         $(EXECUTABLE).exp                                \
         --dll                                            \
         -o $(EXECUTABLE).dll                             \
         $(OBJS) dll_init.o dll_fixup.o \
         -L$(LIBCYGWINPATH)                               \
         $(CYGNUSLIBS)                                    \
         -e _dll_entry@12
	dlltool -k --dllname $(EXECUTABLE).dll \
              --def $(EXECUTABLE).def        \
              --base-file $(EXECUTABLE).base \
              --output-exp $(EXECUTABLE).exp
	ld $(EXECUTABLE).exp                                \
         --dll                                            \
         -o $(EXECUTABLE).dll                             \
         $(OBJS) dll_init.o dll_fixup.o \
         -L$(LIBCYGWINPATH)                               \
         $(CYGNUSLIBS)                                    \
         -e _dll_entry@12
	dlltool -k --dllname $(EXECUTABLE).dll \
              --def $(EXECUTABLE).def        \
              --output-lib $(EXECUTABLE).a
	dllfix $(EXECUTABLE).dll

My dll.def file contains only the following:
EXPORTS
exported_func@16

Where @16 indicates the size of the parammeters on the stack for this
function.
When building a small test program for this DLL, everything compiles ok;
but on execution a dialog-box pops-up complainting that "The TESTDLL.EXE
file is linked to missing export X.DLL:exported_func."
Inspecting the resulting DLL with QuickView, the Export Table section does
show my "exported_func@16", with the @16 mangling but *without* a leading
underscore. Could this be the problem?

I tried adding a second line to my def file with the following:
exported_func=exported_func@16
With this alias (I think it is an alias...) the test program run but
crashes with a message of a possible corrupted stack. Which leads me to
suspect that the function is being called with the incorrect convention.

Any help on getting this to work would be greatly appreciated,

--
JPSousa

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1998-01-12  4:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-01-11 20:11 __stdcall functions in relocatable DLLs Stephan Mueller
  -- strict thread matches above, loose matches on Subject: below --
1998-01-12  2:57 Sergey Okhapkin
1998-01-10 17:22 Joao Pedro Sousa
1998-01-11  9:41 ` Jason Alan Nordwick
1998-01-11 13:15   ` Joao Pedro Sousa
1998-01-12  4:59     ` Benjamin Riefenstahl
1998-01-11 23:40   ` Fergus Henderson

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 read-only IMAP folder(s) and NNTP newsgroup(s).