The original definition of "SendMessageCallbackA" is:
WINUSERAPI
BOOL
WINAPI
SendMessageCallbackA(
IN HWND hWnd,
IN UINT Msg,
IN WPARAM wParam,
IN LPARAM lParam,
IN SENDASYNCPROC lpResultCallBack,
IN ULONG_PTR dwData);
And the definition of "SENDASYNCPROC" is:
typedef VOID (CALLBACK* SENDASYNCPROC)(HWND, UINT, ULONG_PTR, LRESULT);
Now I want to define a function pointer for "SendMessageCallbackA":
BOOL (WINAPI * Real_SendMessageCallbackA)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, SENDASYNCPROC lpResultCallBack, ULONG_PTR dwData)
=SendMessageCallbackA;
But I get an error when I compile the file:
error C2440: 'initializing' : cannot convert from '' to 'int (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long,void (__stdcall *)(struct HWND__ *,unsigned int,unsigned long,long),void *)'
None of the functions with this name in scope match the target type
I couldn't find what the problem is.
What's wrong with my code? How could I define a function pointer for "SendMessageCallbackA"? Who can help me?
Should be &SendMessageCallbackA, I would say, assuming your pointer declaration is OK. Some compilers take it as you wrote it, but it is not the standard AFAIK.
Is this just for practice or is there some unusual reason that you are doing it this way? I ask because User32.dll is included in Windows apps running in User space so defining a function pointer to it feels redundent.
Thank you, webJose! I find what the problem is using your method!
After the compilation, the format of the function "SendMessageCallbackA" becomes:
int (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long,void (__stdcall *)(struct HWND__ *,unsigned int,unsigned long,long),unsigned long)
However, after the compilation, the format of the function pointer "Real_SendMessageCallbackA" becomes:
int (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long,void (__stdcall *)(struct HWND__ *,unsigned int,unsigned long,long),void *)
See the last parameter, which is different.
Thus, I use a new method to define the function pointer which is successful:
BOOL (WINAPI * Real_SendMessageCallbackA)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, SENDASYNCPROC lpResultCallBack, ULONG dwData)
=SendMessageCallbackA;
Computergeek01 and andywestken, thank you anyway!
Do you know the "Detours" tool which will define the "Trampolines" functions?
I use the tool to do some work, which requires to define a function pointer to "SendMessageCallbackA".
I did look into it when it was first released, when I had some performance problems to look at. But you have to pay to use it for non-eductation/non-research uses. And as I needed it for a commercial development project, but couldn't justify the cost for one-off use, ended up having to relay on custom code instead :-(.
The system I was looking at was too complicated for TrueTime - which was available - to handle (processing which took tens of minutes took 24+ hours under TrueTime with full instrumentation).