问题描述
有人可能给我一些建议MS winapi函数的函数指针的提示吗?我试图创建一个指针DefWindowProc(DefWindowProcA / DefWindowProcW),但得到这个错误:
LRESULT(* dwp) HWND,UINT,WPARAM,LPARAM)=& DefWindowProc;
错误C2440:'initializing':无法从
'LRESULT(__stdcall *)(HWND,UINT,WPARAM,LPARAM)'
转换为'LRESULT(__cdecl *) HWND,UINT,WPARAM,LPARAM)'
我不知道我需要使用什么,我不习惯MS ascii /宽宏。顺便说一句,我创建一个函数指针,使一个快速的黑客,不幸的是我没有时间解释为什么 - 但不管怎样,我认为这个问题将有助于需要创建winapi函数指针的人。 / p>
更新:
此代码适用,但我担心这是不好的做法到unicode / ascii编译选项)。我应该定义两个规范?
LRESULT(__stdcall * dwp)(HWND,UINT,WPARAM,LPARAM)=& DefWindowProc;
更新2:
(感谢nobugz):
WNDPROC dwp = DefWindowProc;
修复调用约定不匹配, >
LRESULT(__stdcall * dwp)(HWND,UINT,WPARAM,LPARAM)= DefWindowProc;
typedef可以使这更易读:
typedef LRESULT(__stdcall * WindowProcedure)(HWND,UINT,WPARAM,LPARAM);
...
WindowProcedure dwp = DefWindowProc;
但是,< windows.h>
已经有一个typedef,你可以使用它:
WNDPROC dwp = DefWindowProc;
Please could someone give me a few tips for creating function pointers for MS winapi functions? I'm trying to create a pointer for DefWindowProc (DefWindowProcA/DefWindowProcW) but getting this error:
LRESULT (*dwp)(HWND, UINT, WPARAM, LPARAM) = &DefWindowProc;
error C2440: 'initializing' : cannot convert from
'LRESULT (__stdcall *)(HWND,UINT,WPARAM,LPARAM)'
to 'LRESULT (__cdecl *)(HWND,UINT,WPARAM,LPARAM)'
I can't figure out what I need to use because I am not used to the MS ascii/wide macros. By the way, I'm creating a function pointer to make a quick hack, and unfortunately I don't have time to explain why - but regardless, I think this question will be helpful to people who need to create winapi function pointers.
Update:
This code works, but I'm worried that it is bad practice (and does not adhere to unicode/ascii compile options). Should I define two specifications?
LRESULT (__stdcall* dwp)(HWND, UINT, WPARAM, LPARAM) = &DefWindowProc;
Update 2:
This is nicer (thanks to nobugz):
WNDPROC dwp = DefWindowProc;
Fix the calling convention mismatch like this:
LRESULT (__stdcall * dwp)(HWND, UINT, WPARAM, LPARAM) = DefWindowProc;
A typedef can make this more readable:
typedef LRESULT (__stdcall * WindowProcedure)(HWND, UINT, WPARAM, LPARAM);
...
WindowProcedure dwp = DefWindowProc;
But, <windows.h>
already has a typedef for this, you might as well use it:
WNDPROC dwp = DefWindowProc;
这篇关于winapi函数的函数指针(stdcall / cdecl)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!