Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare an __stdcall function pointer

I tried this

typedef void (* __stdcall MessageHandler)(const Task*); 

This compiles but gives me this warning (VS2003):

warning C4229: anachronism used : modifiers on data are ignored

I want to declare a pointer to a function with stdcall calling convention? What am I doing wrong?

like image 343
Armen Tsirunyan Avatar asked Mar 14 '11 12:03

Armen Tsirunyan


People also ask

What is __ Stdcall in C++?

__stdcall is the calling convention used for the function. This tells the compiler the rules that apply for setting up the stack, pushing arguments and getting a return value.

What is __ Cdecl in C++?

The __cdecl function specifier (C++ only) The __cdecl keyword instructs the compiler to read and write a parameter list by using C linkage conventions. To set the __cdecl calling convention for a function, place the linkage keyword immediately before the function name or at the beginning of the declarator.

How do you call a pointer?

The call by pointer method of passing arguments to a function copies the address of an argument into the formal parameter. Inside the function, the address is used to access the actual argument used in the call. This means that changes made to the parameter affect the passed argument.

What is the difference between Stdcall and Cdecl?

In CDECL arguments are pushed onto the stack in revers order, the caller clears the stack and result is returned via processor registry (later I will call it "register A"). In STDCALL there is one difference, the caller doeasn't clear the stack, the calle do. You are asking which one is faster.


1 Answers

As MSDN says, the correct way to write this is

typedef void (__stdcall *MessageHandler)(const Task*); 
like image 73
Jon Avatar answered Sep 27 '22 16:09

Jon