Solved

How CWinThread derived class can get messages ?

Posted on 2002-03-22
7
793 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:MichaelMaromm
7 Comments
 
LVL 8

Expert Comment

by:VinExpert
ID: 6888424
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
0
 

Author Comment

by:MichaelMaromm
ID: 6888612
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
0
 
LVL 1

Expert Comment

by:pcj0961
ID: 6889320
Is your thread a user interface or worker threads.  worker threads don't have message pumps.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:Chandra V
ID: 6890346
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)

0
 

Author Comment

by:MichaelMaromm
ID: 6891077
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


0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6904948
PLEASE RESPOND HERE TO MICHAEL'S LAST INPUT SO WE CAN FINALIZE THIS.

MOONDANCER - EE MODERATOR
0
 

Accepted Solution

by:
jubjub2 earned 50 total points
ID: 7240396
i just had the same problem MichaelMaromm.
To fix it, you have to make sure the Function that will be called when the thread is sent that messages, returns a void.

Both in the header and in the cpp.

It fixed it in my case.

.h
afx_msg void OnBlah(WPARAM wParam, LPARAM);

.cpp

BEGIN_MESSAGE_MAP(CBlahThread, CWinThread)
//}}AFX_MSG_MAP
ON_THREAD_MESSAGE(WM_BLAHMSG, OnBlah)
END_MESSAGE_MAP()

void CBlahThread::OnBlah(WPARAM wParam, LPARAM lParam)
{
  // Do your work
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now