Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 577
  • Last Modified:

Having trouble using SendMessageCallback

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?

0
jvoros1
Asked:
jvoros1
  • 4
  • 3
  • 2
2 Solutions
 
jkrCommented:
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.
0
 
rajeev_devinCommented:
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.
0
 
jvoros1Author 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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
rajeev_devinCommented:
Simply change the prototype of this function
VOID CALLBACK myFunc(HWND hwnd, UINT uMsg, ULONG dwData, LRESULT lResult)

Nothing required.
0
 
jvoros1Author Commented:
rajeev_devin: That code matches exactly what I have when I get the SENDASYNCPROC errors.
0
 
jkrCommented:
>>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);

?
0
 
jvoros1Author 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
0
 
jvoros1Author Commented:
Figured it out.  I needed to make my function static.

static VOID CALLBACK myFunc(  HWND hwnd,  UINT uMsg,  DWORD dwData,   LRESULT lResult ) {}
0
 
jkrCommented:
>>I needed to make my function static.

Err, you never mentioned that it is about a class member...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now