Re: Is CALLBACK or WINAPI is necessary?

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



"Tom Alter" <Lord2702@xxxxxxx> wrote in message
news:e96wp7hSFHA.688@xxxxxxxxxxxxxxxxxxxxxxx
> Suppose when I am creating my own library, then I will
> not use CALLBACK or WINAPI, but then if caller has the
> problem for not able to use the functions from the library,
> then can caller override this modifiers in his own application?

No.

> Because till this time no one is saying that it is necessary or not.

Well, early on I pointed out that caller and callee _must_ agree on a
caliing convention. On x86 chips and under Win32, what the convention boils
down to (it is a little more in truth) a question as to who pops the
arguments off the stack.

C and C++ programs built with the MS compiler, in the absence of compiler
options to the contrary, operate in a mode in which the both caller pushes
the arguments onto the stack and pops them off the stack onm return.

This allows for variable length argument lists (a practice more common in C
than C++) for a given function. Functions marked STDCALL, CALLBACK, WINAPI,
__stdcall etc move the responsibility for normalizing the strack to the
callee.

Now, since on x86 chips, the return address of a function is on the stack as
well, if caller and callee don't agree on convention chances are that the
function will be called sucessfully but on return wind up in no-man's land.

Regards,
Will


.



Relevant Pages

  • Re: How to define a function which return a matrix to caller by value?
    ... It is when the whole object is copied to the caller stack on return. ... What is returned is the value of the object, not a reference to the heap ... To allocate space, the caller clearly needs to know how much space to allocate. ...
    (comp.lang.fortran)
  • Re: Is it possible to use the value of the PROGRAM ID within the source code?
    ... Every called program has a way of returning to its caller. ... >information about calling history in some sort of hardware stack? ... True but discordant with the culture of operating systems and other languages. ... premise is that called programs may irrationally corrupt parameter values. ...
    (comp.lang.cobol)
  • Re: Stack Overflow
    ... Sub Caller() ... '<<< COMPILER STORES THIS LOCATION ... Sub CalledFunction() ... (Think of it like a stack of plates. ...
    (microsoft.public.excel.programming)
  • Re: StdCall vs. CDecl
    ... __cdecl means that the caller needs to remove the args. ... caller to clean up the stack, while the caller will expect the function to ... why does our VB.NET code work well when the calling convention ...
    (microsoft.public.dotnet.framework.interop)
  • Re: How function calls work
    ... >I'm interested in how the compiler implements function calls, ... >know where these are in memory relative to the current stack pointer ... caller saves registers it wants saved (unless it knows function plans to ... function allocates stack space for all its local data, ...
    (comp.lang.cpp)