Solved

How CWinThread derived class can get messages ?

Posted on 2002-03-22
7
804 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: 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!

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand macro to ask for filename column 8 37
method notes when mouse over in eclipse 5 90
Smart Camera scanning and reading information 3 121
Not needed 13 129
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

762 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