Link to home
Start Free TrialLog in
Avatar of MichaelMaromm
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(CSecondClass,CFirstClass)
  ON_THREAD_MESSAGE(TM_MYTHREAD_MESSAGE,
                     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
Avatar of Vinayak Kumbar
Vinayak Kumbar

Hi,

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
Avatar of MichaelMaromm

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(CThreadWriteInControl,CThreads)
   ON_THREAD_MESSAGE(TM_ITEMARRIVED,OnItemArrived)
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(WPARAM 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(WPARAM wParm, LPARAM lParm)

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


PLEASE RESPOND HERE TO MICHAEL'S LAST INPUT SO WE CAN FINALIZE THIS.

MOONDANCER - EE MODERATOR
ASKER CERTIFIED SOLUTION
Avatar of jubjub2
jubjub2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial