Re: How to export afunction in class?
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Wed, 07 Feb 2007 15:08:17 -0500
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. NewcomerJoseph M. Newcomer [MVP]
<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. NewcomerJoseph M. Newcomer [MVP]
<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
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: How to export afunction in class?
- From: MrAsm
- Re: How to export afunction in class?
- References:
- How to export afunction in class?
- From: Lee Tow
- Re: How to export afunction in class?
- From: Joseph M . Newcomer
- Re: How to export afunction in class?
- From: MrAsm
- Re: How to export afunction in class?
- From: Joseph M . Newcomer
- Re: How to export afunction in class?
- From: MrAsm
- Re: How to export afunction in class?
- From: Joseph M . Newcomer
- Re: How to export afunction in class?
- From: MrAsm
- How to export afunction in class?
- Prev by Date: Re: Escape key
- Next by Date: Re: How to drag a window without holding the button down
- Previous by thread: Re: How to export afunction in class?
- Next by thread: Re: How to export afunction in class?
- Index(es):
Relevant Pages
|