什么是“回调"?在C中声明吗? [英] What does a "CALLBACK" declaration in C do?
问题描述
我在查看 SDL 库中的一些代码时发现了一个声明如下的函数:
I was looking through some code from the SDL library and came across a function declared like this:
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
现在,我是一名 Delphi 编码员.没有 hablo C muy bien,先生.但我记得我大学课程中的语法足够像这样阅读它:
Now, I'm a Delphi coder. No hablo C muy bien, senor. But I remember enough syntax from my college courses to read it like this:
函数名称是 WndProc.参数列表是不言自明的.函数返回类型是 LRESULT.但是,回调"在那里做什么呢?在 Delphi 中,任何函数都可以用作回调;你只需要传递正确类型的函数指针.C 不能那样工作有什么特别的原因吗?或者它意味着什么不同的东西?
Function name is WndProc. Argument list is pretty self-explanatory. Function return type is LRESULT. But what in the world is that "CALLBACK" doing there? In Delp any function can be used as a callback; you just need to pass the right type of function pointer. Is there any particular reason why C doesn't work that way? Or does it mean something different?
推荐答案
CALLBACK"是一个调用约定.还有其他类型的调用约定.CALLBACK 与 __stdcall 相同.
The "CALLBACK" is a calling convention. There are other kinds of calling conventions. CALLBACK is the same as __stdcall.
http://www.codeguru.com/cpp/cpp/cpp_mfc/callbacks/article.php/c10557
Raymond Chen 的博客中的更多信息:
Some more information at Raymond Chen's blog:
http://blogs.msdn.com/oldnewthing/存档/2004/01/08/48616.aspx
这篇关于什么是“回调"?在C中声明吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!