1

In MFC VC++, setTimer function is setted using a CALLBACK procedure. From the link I read that

A function that is marked with __stdcall uses the standard calling convention so named because all Win32 API functions (except the few that take variable arguments) use it.

And from that, this is what I have understand, ALL THE VC++ MFC FUNCTIONS USE __stdcall as their calling conversions.

And CALLBACK is defined as follows....

 #define CALLBACK __stdcall

What I have read: Preceding a function with CALLBACK is used to emphasise that the particular function will be called automatically whenever necessary(like in this setTimer case or onClick case in javascript),

My doubt is , In MFC VC++ all functions(except the few that take variable arguments) has a default calling convention of __stdcall. Hence either preceding or not preceding a function with CALLBACK or WINAPI or PASCAL has a same effect?

Muthu Ganapathy Nathan
  • 3,199
  • 16
  • 47
  • 77

1 Answers1

0

Is it absolutely necessary for the computer? It depends on the context. When you mismatch the calling convention, you could either get lucky because the datatypes on the stack happen to match the requirements of the API, or it could fail miserably when your code is run on a different architecture like x64 and crashes every time.

Is it absolutely necessary for the maintenance programmer? Yes, it is. You know, the poor person who will have to figure out your non-standard conventions and clever "optimizations." Some day, that poor person might be you.

The compiler was yelling at you for a reason when you tried to subvert the API.

user244795
  • 698
  • 6
  • 14