Click here to Skip to main content
16,006,341 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionis this possible? Pin
29-Aug-01 5:11
suss29-Aug-01 5:11 
AnswerRe: is this possible? Pin
#realJSOP29-Aug-01 5:28
professional#realJSOP29-Aug-01 5:28 
AnswerRe: is this possible? Pin
MartinL29-Aug-01 7:15
MartinL29-Aug-01 7:15 
QuestionHow to initialize the follow parameter in "NETRESOURCE"? Pin
Maer72729-Aug-01 4:56
Maer72729-Aug-01 4:56 
AnswerRe: How to initialize the follow parameter in Pin
Paolo Messina29-Aug-01 12:43
professionalPaolo Messina29-Aug-01 12:43 
GeneralRe: How to initialize the follow parameter in Pin
Maer72729-Aug-01 21:35
Maer72729-Aug-01 21:35 
QuestionWhy add "WINAPI" ahead of a function? Pin
Maer72729-Aug-01 4:55
Maer72729-Aug-01 4:55 
AnswerRe: Why add Pin
Joaquín M López Muñoz29-Aug-01 6:05
Joaquín M López Muñoz29-Aug-01 6:05 
WINAPI specifies the calling convention of the function. The calling convention is the set of rules followed to pass arguments to and invoke a function. Some aspects a calling convention must define are
  • Whether parameters are stored in registers or in the stack,
  • the order in which parameters are stored in the stack (first parameter the first to be pushed or the other way round),
  • whose responsibility it is to clean the stack after return,
  • how the return parameter is passed from the function to the invoker.
So, different languages typically specify different calling conventions (notably, the Pascal calling convention is that the callee clean the stack before returning, whereas in C it is the caller that does the job). If a function is invoked with a different calling convention than expected, crash is almost sure to happen.
The language C (as implemented by Microsoft) allows the specification of the calling convention of a function so that you can invoke it even if it does not follow the C calling convention. Some calling conventions are:
  • __cdecl, the C default calling convention,
  • __stdcall, aka PASCAL,
  • __fastcall, __thiscall, etc.
WINAPI is simply a macro for __stdcall, and ensures that your program calls Windows APIs the Pascal way.
Why do Win32 APIs use the Pascal calling convention instead of __cdecl? Remember that these functions inhabit global DLLs of the system and are invoked by different programs written in different languages, so they just had to stick to some particular convention.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
GeneralRe: Why add Pin
Maer72729-Aug-01 20:02
Maer72729-Aug-01 20:02 
GeneralRe: Why add Pin
Joaquín M López Muñoz29-Aug-01 20:05
Joaquín M López Muñoz29-Aug-01 20:05 
GeneralRe: Why add Pin
Maer72729-Aug-01 22:10
Maer72729-Aug-01 22:10 
GeneralData Compression Alogrithm Pin
Ganesh Ramaswamy29-Aug-01 4:47
Ganesh Ramaswamy29-Aug-01 4:47 
GeneralRe: Data Compression Alogrithm Pin
Chris Losinger29-Aug-01 5:33
professionalChris Losinger29-Aug-01 5:33 
GeneralWhat's wrong with the convertion?:ostringstream->CComVariant Pin
29-Aug-01 4:07
suss29-Aug-01 4:07 
GeneralSubclassing Pin
ManjuG29-Aug-01 3:20
ManjuG29-Aug-01 3:20 
GeneralRe: Subclassing Pin
Carlos Antollini29-Aug-01 3:51
Carlos Antollini29-Aug-01 3:51 
GeneralSubclassing Pin
ManjuG29-Aug-01 4:13
ManjuG29-Aug-01 4:13 
GeneralRe: Subclassing Pin
Carlos Antollini29-Aug-01 7:19
Carlos Antollini29-Aug-01 7:19 
GeneralRe: Subclassing Pin
ManjuG29-Aug-01 20:54
ManjuG29-Aug-01 20:54 
GeneralChanging Icon for an .exe file Pin
Vijay S29-Aug-01 2:52
Vijay S29-Aug-01 2:52 
GeneralRe: Changing Icon for an .exe file Pin
Joaquín M López Muñoz29-Aug-01 6:10
Joaquín M López Muñoz29-Aug-01 6:10 
GeneralRe: Changing Icon for an .exe file Pin
Vijay S30-Aug-01 19:37
Vijay S30-Aug-01 19:37 
GeneralCOMM problem Pin
Sandeep Shetty29-Aug-01 1:48
Sandeep Shetty29-Aug-01 1:48 
GeneralSimple/Extended MAPI & CDO Pin
AJ12328-Aug-01 23:38
AJ12328-Aug-01 23:38 
GeneralBeginner's question about calendar controls Pin
28-Aug-01 23:14
suss28-Aug-01 23:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.