3

I have come across a typedef in some code which is this:

typedef void (NE_API *NeWindowProcCallback)(void* hWnd, NEuint uMsgId, NEuint wParam, NEuint64 lParam);

however, I am unfamiliar with this syntax. can anyone explain this?

Also, if I jump to the declaration of NE_API, I find this:

#   define NE_API __stdcall

I thought this may be relevant to the answer, and an explanation of this also would be very appreciated. Thank you.

Dollarslice
  • 9,917
  • 22
  • 59
  • 87

4 Answers4

5

That is the typedef of a function pointer for which the function which returns void, has __stdcall calling convention, and accepts four parameters. So you can assign the address of any function which has this signature to a variable of type NeWindowProcCallback. This variable can then be passed as a parameter to other functions which expect a callback function. See this for more details on how function pointers can be used.

Community
  • 1
  • 1
Naveen
  • 74,600
  • 47
  • 176
  • 233
1

You can see what __stdcall is here: What is __stdcall? As for the typedef - this is the way to typedef a function. Now the type NeWindowProcCallback will be a pointer to a function taking arguments of type (void* hWnd, NEuint uMsgId, NEuint wParam, NEuint64 lParam).

So you can do:

void  foo(void* hWnd, NEuint uMsgId, NEuint wParam, NEuint64 lParam);


int main() {
  NeWindowProcCallback my_func = foo;
  ....
  // use the pointer
}
Community
  • 1
  • 1
Ivaylo Strandjev
  • 69,226
  • 18
  • 123
  • 176
1

NeWindowProcCallback is type for a function pointer. It takes the parameters void* hWnd, NEuint uMsgId, NEuint wParam, NEuint64 lParam, and returns void.

__stdcall is the calling convention, which determines how arguments should be passed in the generated calling assembly code.

James M
  • 18,506
  • 3
  • 48
  • 56
0

the typedef defines NeWindowProcCallback as a type that stores a pointer to a function that returns void and takes (void* hWnd, NEuint uMsgId, NEuint wParam, NEuint64 lParam) as parameters

Smittii
  • 187
  • 1
  • 10