Re: How to export afunction in class?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



OK, that's a different issue. Since I keep as far from VB as I can manage, I never hit
that. But this would justify using a .DEF file to create the names. OTOH, if VB is
calling, wouldn't it expect the @n decorations at the end?

call->ret->add SP is the CDECL convention
call->retn is the STDCALL convention

But more critical, the retn which strips the parameters off the stack takes place
CONCURRENTLY with the fetch of the top of stack to the IP, so it all occurs in a SINGLE
clock cycle (the top of stack is in the stack cache on the CPU chip).

I've just never wanted to go near VB if I could avoid it, so I have no experience to offer
in that regard. But if it wants stdcall, the cdecl will definitely screw the stack over.
joe


On Wed, 07 Feb 2007 17:59:07 GMT, MrAsm <mrasm@xxxxxxx> wrote:

On Wed, 07 Feb 2007 11:12:37 -0500, Joseph M. Newcomer
<newcomer@xxxxxxxxxxxx> wrote:

Joe: your posts are very interesting as usual.

But I was not choosing STDCALL for performances (I was unaware that
STDCALL gives better performance than CDECL - thank you for this
information). I simply choosed STDCALL because I read that STDCALL is
the calling convention required by Visual Basic clients to call
C-interface DLL code.

So, for those DLL having a C interface, that I want to make callable
from Visual Basic clients, I thought I had to use STDCALL (and so .DEF
files, to avoid name decoration).

(Of course, to make C++ code available to VB clients, I may choose to
build COM DLLs with ATL or MFC, but it is more complex in many cases
than simple C-interface DLL + STDCALL).

Maybe am I wrong about STDCALL necessity for VB?
Is it also possible to use CDECL for functions designed to be callable
also by VB clients?
I read that stack corruption occurs when VB calls DLL CDECL-functions.

Thanks in advance,
MrAsm



No, but I rarely find that I need stdcall when calling the exported functions of a DLL.
Actually, let me rephrase that: I've never found a need to use stdcall when calling the
functions of a DLL. I trade off a couple extra instructions against the convenience and
robustness of using CDECL, and it means there is no real value to stdcall. So I've never
worried about it.

Why does stdcall make a difference? Unless you are in the inner loop of some intense
computation and calling your DLL on every iteration, the performance issue would never
matter. I'll trade off performance vs. convenience at this level any time, because I
don't need the performance when going into a DLL.
joe

On Wed, 07 Feb 2007 07:34:46 GMT, MrAsm <mrasm@xxxxxxx> wrote:

On Wed, 07 Feb 2007 01:07:02 -0500, Joseph M. Newcomer
<newcomer@xxxxxxxxxxxx> wrote:

In that case, you could use CDECL and it will all work right anyway.
joe

You're right that CDECL doesn't decorate names, but it has different
calling convention than STDCALL, so if I want the STDCALL's calling
conventions (e.g. called function pops its own arguments from the
stack) and I want no name decoration, I must use .DEF files.

Or is there another way to have STDCALL calling convention and no
decoration *without* using .DEF files?

Thank you
MrAsm
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Problems with big modules of subroutines
    ... So if you substitute an integer for a real, or a character for 2 ... What you are describing is the IA-32 Windows STDCALL calling ... convention, defined by Microsoft, which has a naming convention that ... be popped off the stack when the routine returns. ...
    (comp.lang.fortran)
  • Re: calling convention stdcalll and cdecl call
    ... parameters from the stack. ... It uses cdecl convention, where the ... How would your hypothetical stdcall printf know to remove 12 bytes worth ...
    (microsoft.public.vc.language)
  • Re: how create a dll callback ?
    ... Declare a variable of procedural type in the DLL, ... orthodoxy prescribes the use of stdcall. ...
    (alt.comp.lang.borland-delphi)
  • Re: VB6 DLL Assembly Compile Link how???
    ... I know that my DLL's calling convention must be a StdCall. ... removes the arguments from the stack; ... including a sample DLL ...
    (microsoft.public.vb.general.discussion)
  • Re: Problems linking a BCB-DLL (.lib) under MSVC
    ... I agree with you, Borland's implib is excellent. ... DLL file, exporting pure C functions, and you ... extern "C" with __stdcall, unless a DEF file is present. ... must have a DEF file, in order to prevent the name mangling. ...
    (microsoft.public.dotnet.languages.vc)