We help IT Professionals succeed at work.

Having trouble using SendMessageCallback

jvoros1
jvoros1 asked
on
Medium Priority
614 Views
Last Modified: 2008-01-09
I'm trying to use SendMessageCallback and I've found a number of pages which cover the subject but none of them want to work for me.

eg:
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_11664840.html?query=sendmessagecallback&clearTAFilter=true


What I have is an ATL ActiveX control where I want to Asynchronously process a function and continue processing the message queue like normal (Which is why I can't use sendMessage (because that bypasses the queue.  See answer #2 here: http://www.experts-exchange.com/Programming/Programming_Platforms/Win_Prog/Q_10149991.html?query=sendmessagecallback&clearTAFilter=true ).

This is my code:

SendMessageCallback(myClass->mhWndPlugin, WM_CUSTOMDRAW, NULL, NULL, myFunc, 0);

And my function is defined as either one of these:

// static void myFunc(HWND hwnd, UINT uMsg, ULONG_PTR dwData, LRESULT lResult) { return;}
VOID CALLBACK myFunc(  HWND hwnd,  UINT uMsg,  ULONG_PTR dwData,   LRESULT lResult ) { return; }

This is the error that I get when I try to compile:
error C2065: 'myFunc' : undeclared identifier
error C3861: 'myFunc': identifier not found, even with argument-dependent lookup

OR I get

error C2664: 'SendMessageCallbackW' : cannot convert parameter 5 from 'void (HWND,UINT,ULONG_PTR,LRESULT)' to 'SENDASYNCPROC'
        None of the functions with this name in scope match the target type
error C2664: 'SendMessageCallbackW' : cannot convert parameter 5 from 'void (HWND,UINT,ULONG_PTR,LRESULT)' to 'SENDASYNCPROC'
        None of the functions with this name in scope match the target type

depending on if I put the function inside or outside of the class.  Can anyone tell me whats wrong?

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2012
Commented:
Use

VOID CALLBACK myFunc(  HWND hwnd,  UINT uMsg,  DWORD dwData,   LRESULT lResult ) { return; }

SendMessageCallback(myClass->mhWndPlugin, WM_CUSTOMDRAW, NULL, NULL, myFunc, 0);

or


SendMessageCallback(myClass->mhWndPlugin, WM_CUSTOMDRAW, NULL, NULL, (SENDASYNCPROC) myFunc, 0);

if you want to enforce the usage of a different parameter type.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
I tried your and it looked very strange to me.
As jkr has suggested it will be something like that.
I tried this
VOID CALLBACK myFunc(HWND hwnd, UINT uMsg, ULONG dwData, LRESULT lResult)

In fact the fourth parameter of 'SENDASYNCPROC' is ULONG and not ULONG_PTR.

Author

Commented:
I've tried every combonation of the above two solutions and I still can't get it to work.  I'm getting this error now:

error C2664: 'SendMessageCallbackW' : cannot convert parameter 5 from 'void (HWND,UINT,DWORD,LRESULT)' to 'SENDASYNCPROC'
        None of the functions with this name in scope match the target type
Simply change the prototype of this function
VOID CALLBACK myFunc(HWND hwnd, UINT uMsg, ULONG dwData, LRESULT lResult)

Nothing required.

Author

Commented:
rajeev_devin: That code matches exactly what I have when I get the SENDASYNCPROC errors.
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
>>I've tried every combonation

also

VOID CALLBACK myFunc(  HWND hwnd,  UINT uMsg,  DWORD dwData,   LRESULT lResult ) { return; }

SendMessageCallback(myClass->mhWndPlugin, WM_CUSTOMDRAW, NULL, NULL, (SENDASYNCPROC) myFunc, 0);

?

Author

Commented:
That particular one gives me
error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'SENDASYNCPROC'
        None of the functions with this name in scope match the target type

Author

Commented:
Figured it out.  I needed to make my function static.

static VOID CALLBACK myFunc(  HWND hwnd,  UINT uMsg,  DWORD dwData,   LRESULT lResult ) {}
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
>>I needed to make my function static.

Err, you never mentioned that it is about a class member...
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.