MichaelMaromm
asked on
How CWinThread derived class can get messages ?
Hi
I've created a class 'CSecondClass' that is derived by 'CFirstClass', which is derived by CWinThread.
I want that CSecondClass will get a custom messages
(e.g. WM_USER+19)
I've tried to do it by a message map :
#define TM_MYTHREAD_MESSAGE WM_USER+19
BEGIN_MESSAGE_MAP(CSecondC lass,CFirs tClass)
ON_THREAD_MESSAGE(TM_MYTHR EAD_MESSAG E,
OnMyThreadMessageHandler)
END_MESSAGE_MAP()
The problem is that the compiler writes :
'type cast' : cannot convert from 'long (__thiscall CSecondClass::*)(unsigned int,long)' to
'void (__thiscall CWinThread::*)(unsigned int,long)'
Please tell me, how to use the message map, that my class will can get the wanted message without getting any error about converting (CSecondClass::*)(unsigned int,long) to (CWinThread::*)(unsigned int,long)'.
Thanks
Michael
I've created a class 'CSecondClass' that is derived by 'CFirstClass', which is derived by CWinThread.
I want that CSecondClass will get a custom messages
(e.g. WM_USER+19)
I've tried to do it by a message map :
#define TM_MYTHREAD_MESSAGE WM_USER+19
BEGIN_MESSAGE_MAP(CSecondC
ON_THREAD_MESSAGE(TM_MYTHR
OnMyThreadMessageHandler)
END_MESSAGE_MAP()
The problem is that the compiler writes :
'type cast' : cannot convert from 'long (__thiscall CSecondClass::*)(unsigned int,long)' to
'void (__thiscall CWinThread::*)(unsigned int,long)'
Please tell me, how to use the message map, that my class will can get the wanted message without getting any error about converting (CSecondClass::*)(unsigned
Thanks
Michael
ASKER
Hi VinExpert
I changed the returned data type as you suggested, but now the compiler's errors are :
error C2440: 'type cast' : cannot convert from
'void(__thiscall CThreadWriteInControl::*)
(unsigned int,long)' to 'void (__thiscall CWinThread::*)(unsigned int,long)'
error C2440: 'type cast' : cannot convert from 'void (__thiscall CThreadWriteInControl::*)( unsigned int,long)' to
'void (__thiscall CWinThread::*)(void)'
Pointers to members have different representations; cannot cast between them.
-------------------------- ---------- ---------- ---------- -
The message map is :
BEGIN_MESSAGE_MAP(CThreadW riteInCont rol,CThrea ds)
ON_THREAD_MESSAGE(TM_ITEMA RRIVED,OnI temArrived )
END_MESSAGE_MAP()
When CThreadWriteInControl is derived by CThreads, which is derived by CWinThread.
The OnItemArrived is declared in 'CThreadWriteInControl'
as the follows :
afx_msg virtual void OnItemArrived
(WPARAM wParam,LPARAM lParam) {}
This function member is implemented in other classes that are derived by CThreadWriteInControl.
Please tell me, How to fix it.
Michael
I changed the returned data type as you suggested, but now the compiler's errors are :
error C2440: 'type cast' : cannot convert from
'void(__thiscall CThreadWriteInControl::*)
(unsigned int,long)' to 'void (__thiscall CWinThread::*)(unsigned int,long)'
error C2440: 'type cast' : cannot convert from 'void (__thiscall CThreadWriteInControl::*)(
'void (__thiscall CWinThread::*)(void)'
Pointers to members have different representations; cannot cast between them.
--------------------------
The message map is :
BEGIN_MESSAGE_MAP(CThreadW
ON_THREAD_MESSAGE(TM_ITEMA
END_MESSAGE_MAP()
When CThreadWriteInControl is derived by CThreads, which is derived by CWinThread.
The OnItemArrived is declared in 'CThreadWriteInControl'
as the follows :
afx_msg virtual void OnItemArrived
(WPARAM wParam,LPARAM lParam) {}
This function member is implemented in other classes that are derived by CThreadWriteInControl.
Please tell me, How to fix it.
Michael
Is your thread a user interface or worker threads. worker threads don't have message pumps.
The standard convention for a message handler is
LRESULT YourClass::YourHandler(WPA RAM wParm,LPARAM lParm)
This is strict in VC 7.0
If you are using VC 6.0
you can use
void YourClass::YourHandler()
(or)
void YourClass::YourHandler(WPA RAM wParm, LPARAM lParm)
LRESULT YourClass::YourHandler(WPA
This is strict in VC 7.0
If you are using VC 6.0
you can use
void YourClass::YourHandler()
(or)
void YourClass::YourHandler(WPA
ASKER
Hi cvallabhaneni,
Thanks for your answer, but when I try to use:
void MyClass::MyHandler(WPARAM wParm, LPARAM lParm)
I get the compiler error :
'type cast' : cannot convert from
'void(__thiscall CMyClass::*)
(unsigned int,long)' to 'void (__thiscall CWinThread::*)(unsigned int,long)'.
By The Way : 'CMyClass' is derived by 'COtherClass', which is derived by 'CWinThread'.
Michael
Thanks for your answer, but when I try to use:
void MyClass::MyHandler(WPARAM wParm, LPARAM lParm)
I get the compiler error :
'type cast' : cannot convert from
'void(__thiscall CMyClass::*)
(unsigned int,long)' to 'void (__thiscall CWinThread::*)(unsigned int,long)'.
By The Way : 'CMyClass' is derived by 'COtherClass', which is derived by 'CWinThread'.
Michael
PLEASE RESPOND HERE TO MICHAEL'S LAST INPUT SO WE CAN FINALIZE THIS.
MOONDANCER - EE MODERATOR
MOONDANCER - EE MODERATOR
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just change ur thread function's return datatype from long to void and check it.
It will be helpfull if u post some relevant code of thread function declaration here.
Try it out.
VinExpert